Skip to contentSkip to conversation

classes/ptest-python-pytest: simplify python ptest file overriding

PATCH Superseded Derek Straka 2 participants 2 messages Jan 8, 2025 – Jan 10, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 classes/ptest-python-pytest: simplify python ptest file overriding

The complexity of overriding files from the bbclass made the behavior at times hard to follow and predict. This change replaces the default file with a heredoc equivalent that creates a default file if the user does not provide their own version of run-ptest in the SRC_URI.

---
 .../ptest-python-pytest.bbclass               | 22 ++++++++++++-------
 meta/files/ptest-python-pytest/run-ptest      |  3 ---
 2 files changed, 14 insertions(+), 11 deletions(-)
 delete mode 100755 meta/files/ptest-python-pytest/run-ptest
meta/classes-recipe/ptest-python-pytest.bbclass +14 -8
index 801079e6ab..398a238300 100644
@@ -6,19 +6,25 @@
 
 inherit ptest
 
-FILESEXTRAPATHS:prepend := "${COREBASE}/meta/files:"
-
-SRC_URI:append = "\
-    file://ptest-python-pytest/run-ptest \
-"
-
 # Overridable configuration for the directory within the source tree
 # containing the pytest files
 PTEST_PYTEST_DIR ?= "tests"
 
 do_install_ptest() {
-	if [ ! -f ${D}${PTEST_PATH}/run-ptest ]; then
-		install -m 0755 ${UNPACKDIR}/ptest-python-pytest/run-ptest ${D}${PTEST_PATH}
+    # Check if the recipe provides its own version of run-ptest
+    # If nothing exists in the SRC_URI, dynamically create a 
+    # run-test script of "last resort" that has the default
+    # pytest behavior.
+    # 
+    # Users can override this behavior by simply including a
+    # custom script (run-ptest) in the source file list
+	if [ ! -f "${UNPACKDIR}${PTEST_PATH}/run-ptest" ]; then
+		cat > ${D}${PTEST_PATH}/run-ptest << EOF
+#!/bin/sh
+pytest --automake
+EOF
+        # Ensure the newly created script has the execute bit set
+        chmod 755 ${D}${PTEST_PATH}/run-ptest
 	fi
     if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then
         install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}
meta/files/ptest-python-pytest/run-ptest deleted +0 -3
deleted file mode 100755
index 8d2017d39c..0000000000
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-pytest --automake
Signature · 1 line
2.34.1
#1 lore raw
Quoted 47 lines · Derek Straka via lists.openembedded.org

The complexity of overriding files from the bbclass made the behavior at times hard to follow and predict. This change replaces the default file with a heredoc equivalent that creates a default file if the user does not provide their own version of run-ptest in the SRC_URI.

---
 .../ptest-python-pytest.bbclass               | 22 ++++++++++++------- meta/files/ptest-python-pytest/run-ptest      |  3 ---

 2 files changed, 14 insertions(+), 11 deletions(-)

 delete mode 100755 meta/files/ptest-python-pytest/run-ptest

meta/classes-recipe/ptest-python-pytest.bbclass +0 -0
index 801079e6ab..398a238300 100644
@@ -6,19 +6,25 @@


 inherit ptest

meta/classes-recipe/ptest-python-pytest.bbclass +0 -6
-FILESEXTRAPATHS:prepend := "${COREBASE}/meta/files:"
-
-SRC_URI:append = "\
-    file://ptest-python-pytest/run-ptest \
-"
-

 # Overridable configuration for the directory within the source tree

 # containing the pytest files
 PTEST_PYTEST_DIR ?= "tests"
 
 do_install_ptest() {
meta/classes-recipe/ptest-python-pytest.bbclass +14 -2
-	if [ ! -f ${D}${PTEST_PATH}/run-ptest ]; then
-		install -m 0755 ${UNPACKDIR}/ptest-python-pytest/run-ptest ${D}${PTEST_PATH}
+    # Check if the recipe provides its own version of run-ptest
+    # If nothing exists in the SRC_URI, dynamically create a 
+    # run-test script of "last resort" that has the default
+    # pytest behavior.
+    # 
+    # Users can override this behavior by simply including a
+    # custom script (run-ptest) in the source file list
+	if [ ! -f "${UNPACKDIR}${PTEST_PATH}/run-ptest" ]; then
+		cat > ${D}${PTEST_PATH}/run-ptest << EOF
+#!/bin/sh
+pytest --automake
+EOF
+        # Ensure the newly created script has the execute bit set
+        chmod 755 ${D}${PTEST_PATH}/run-ptest
Quoted 1 line

  fi

Thanks for the new version of the patch, I think this is a good change.

I did have to tweak the whitespace in the patch above, we use tabs to indent shell and this function was mismatching with the rest of the existing function.

Quoted 2 lines

     if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}

Secondly, there were ptest failures with this patch:

https://valkyrie.yoctoproject.org/#/builders/61/builds/713/steps/12/logs/stdio
https://valkyrie.yoctoproject.org/#/builders/73/builds/716/steps/12/logs/stdio

https://valkyrie.yocto.io/pub/non-release/20250109-78/testresults/qemuarm64-ptest/python3-pefile.log
https://valkyrie.yocto.io/pub/non-release/20250109-78/testresults/qemuarm64-ptest/python3-libarchive-c.log

Cheers,

Richard