]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes/ptest-python-pytest: add a new class to consolidate pytest ptest functionality
authorDerek Straka <derek@asterius.io>
Wed, 18 Dec 2024 18:05:47 +0000 (18:05 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 8 Jan 2025 12:36:45 +0000 (12:36 +0000)
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

[RP: Minor whitespace tweaks to shell function and missing prepend space]
Signed-off-by: Derek Straka <derek@asterius.io>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/ptest-python-pytest.bbclass [new file with mode: 0644]
meta/files/ptest-python-pytest/run-ptest [new file with mode: 0755]

diff --git a/meta/classes-recipe/ptest-python-pytest.bbclass b/meta/classes-recipe/ptest-python-pytest.bbclass
new file mode 100644 (file)
index 0000000..6d4f16a
--- /dev/null
@@ -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 (executable)
index 0000000..8d2017d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+pytest --automake