xref: /openbmc/openbmc/poky/meta/classes-recipe/ptest-python-pytest.bbclass (revision eaae0b339f806200d8722cb09e5e3b83c15a5956)
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7inherit ptest
8
9# Overridable configuration for the directory within the source tree
10# containing the pytest files
11PTEST_PYTEST_DIR ?= "tests"
12
13do_install_ptest() {
14	# Check if the recipe provides its own version of run-ptest
15	# If nothing exists in the SRC_URI, dynamically create a
16	# run-test script of "last resort" that has the default
17	# pytest behavior.
18	#
19	# Users can override this behavior by simply including a
20	# custom script (run-ptest) in the source file list
21	if [ ! -f "${UNPACKDIR}/run-ptest" ]; then
22		cat > ${D}${PTEST_PATH}/run-ptest << EOF
23#!/bin/sh
24pytest --automake
25EOF
26		# Ensure the newly created script has the execute bit set
27		chmod 755 ${D}${PTEST_PATH}/run-ptest
28	fi
29	if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then
30		install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}
31		cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/
32	fi
33}
34
35FILES:${PN}-ptest:prepend = "${PTEST_PATH}/*"
36
37RDEPENDS:${PN}-ptest:prepend = "python3-pytest python3-unittest-automake-output "
38