diff mbox series

[PATCHv3,1/2] classes/ptest-python-pytest: add a new class to consolidate pytest ptest functionality

Message ID 20241218180548.3539070-1-derek@asterius.io
State New
Headers show
Series [PATCHv3,1/2] classes/ptest-python-pytest: add a new class to consolidate pytest ptest functionality | expand

Commit Message

Derek Straka Dec. 18, 2024, 6:05 p.m. UTC
A large number of python packages leverage the pytest unit test
framework for their ptest functionality.  Currently, many of the tests
have duplicate code for:
    1. Installing pytest files
    2. Declaring ptest dependencies
    3. Script for executing tests (run-ptes)

To simplify adding common pytest based ptests, added a new class
enabling base functionality.  Users can also override the location of
the pytest files in addition to using their own version of run-ptest

Signed-off-by: Derek Straka <derek@asterius.io>
---
 .../ptest-python-pytest.bbclass               | 31 +++++++++++++++++++
 meta/files/ptest-python-pytest/run-ptest      |  3 ++
 2 files changed, 34 insertions(+)
 create mode 100644 meta/classes-recipe/ptest-python-pytest.bbclass
 create mode 100755 meta/files/ptest-python-pytest/run-ptest

Comments

Quentin Schulz Dec. 19, 2024, 11:09 a.m. UTC | #1
Hi Derek,

On 12/18/24 7:05 PM, Derek Straka via lists.openembedded.org wrote:
> A large number of python packages leverage the pytest unit test
> framework for their ptest functionality.  Currently, many of the tests
> have duplicate code for:
>      1. Installing pytest files
>      2. Declaring ptest dependencies
>      3. Script for executing tests (run-ptes)
> 
> To simplify adding common pytest based ptests, added a new class
> enabling base functionality.  Users can also override the location of
> the pytest files in addition to using their own version of run-ptest
> 
> Signed-off-by: Derek Straka <derek@asterius.io>
> ---
>   .../ptest-python-pytest.bbclass               | 31 +++++++++++++++++++
>   meta/files/ptest-python-pytest/run-ptest      |  3 ++
>   2 files changed, 34 insertions(+)
>   create mode 100644 meta/classes-recipe/ptest-python-pytest.bbclass
>   create mode 100755 meta/files/ptest-python-pytest/run-ptest
> 
> diff --git a/meta/classes-recipe/ptest-python-pytest.bbclass b/meta/classes-recipe/ptest-python-pytest.bbclass
> new file mode 100644
> index 0000000000..801079e6ab
> --- /dev/null
> +++ b/meta/classes-recipe/ptest-python-pytest.bbclass
> @@ -0,0 +1,31 @@
> +#
> +# Copyright OpenEmbedded Contributors
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +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}
> +	fi

Still same issue as v2. You need to check the presence of 
${UNPACKDIR}/ptest-python-pytest/run-ptest not 
${D}${PTEST_PATH}/run-ptest otherwise a leftover workdir will prevent 
updating the run-ptest script.

This should be preventable if we simply get run-ptest from this class 
installed in UNPACKDIR directly, as ptest.bbclass does that already. I 
think it makes sense to reuse as much as possible from the original 
class for ptest?

> +    if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then
> +        install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}
> +        cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/
> +    fi
> +}
> +
> +FILES:${PN}-ptest:prepend = "${PTEST_PATH}/*"

This one should have ${PTEST_PYTEST_DIR} as well to match what you're 
doing above. Otherwise it's useless since ptest.bbclass that we inherit 
at the top already defines this.

I'm out of office for the next 3 weeks in 4 hours, so anything not 
settled by then I won't be able to answer until then, up to 
maintainers/other reviewers to chime in at that point :)

Cheers,
Quentin
diff mbox series

Patch

diff --git a/meta/classes-recipe/ptest-python-pytest.bbclass b/meta/classes-recipe/ptest-python-pytest.bbclass
new file mode 100644
index 0000000000..801079e6ab
--- /dev/null
+++ b/meta/classes-recipe/ptest-python-pytest.bbclass
@@ -0,0 +1,31 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+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}
+	fi
+    if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then
+        install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}
+        cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/
+    fi
+}
+
+FILES:${PN}-ptest:prepend = "${PTEST_PATH}/*"
+
+RDEPENDS:${PN}-ptest:prepend = "python3-pytest python3-unittest-automake-output"
diff --git a/meta/files/ptest-python-pytest/run-ptest b/meta/files/ptest-python-pytest/run-ptest
new file mode 100755
index 0000000000..8d2017d39c
--- /dev/null
+++ b/meta/files/ptest-python-pytest/run-ptest
@@ -0,0 +1,3 @@ 
+#!/bin/sh
+
+pytest --automake