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