commit:     5130c0197421a125eff7d98c5d0f7ae284acddce
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  6 10:55:41 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Mar  8 07:52:30 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5130c019

python-utils-r1.eclass: Introduce epytest helper

Introduce an epytest helper to call pytest with the standard set
of options, and the standard error message.  While
distutils_enable_tests made running pytest a lot easier, there are still
many cases when python_test() needs to be redefined in order to pass
additional options or perform additional actions.  Having the extra
helper will reduce code duplication and make it easier to change
the standard options.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index dcc441b8209..1b2e2ccde8e 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1278,6 +1278,29 @@ build_sphinx() {
        HTML_DOCS+=( "${dir}/_build/html/." )
 }
 
+# @FUNCTION: epytest
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Run pytest, passing the standard set of pytest options, followed
+# by user-specified options.
+#
+# This command dies on failure and respects nonfatal in EAPIs supporting
+# nonfatal die.
+epytest() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
+
+       local die_args=()
+       [[ ${EAPI} != [45] ]] && die_args+=( -n )
+
+       set -- "${EPYTHON}" -m pytest -vv "${@}"
+
+       echo "${@}" >&2
+       "${@}" || die "${die_args[@]}" "pytest failed with ${EPYTHON}"
+       return ${?}
+}
+
 # -- python.eclass functions --
 
 _python_check_dead_variables() {

Reply via email to