Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/3] python-utils-r1.eclass: Introduce epytest helper
Date: Sat, 06 Mar 2021 11:01:21
Message-Id: 20210306110110.384691-1-mgorny@gentoo.org
1 Introduce an epytest helper to call pytest with the standard set
2 of options, and the standard error message. While
3 distutils_enable_tests made running pytest a lot easier, there are still
4 many cases when python_test() needs to be redefined in order to pass
5 additional options or perform additional actions. Having the extra
6 helper will reduce code duplication and make it easier to change
7 the standard options.
8
9 Signed-off-by: Michał Górny <mgorny@g.o>
10 ---
11 eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++
12 1 file changed, 23 insertions(+)
13
14 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
15 index dcc441b82098..1b2e2ccde8e5 100644
16 --- a/eclass/python-utils-r1.eclass
17 +++ b/eclass/python-utils-r1.eclass
18 @@ -1278,6 +1278,29 @@ build_sphinx() {
19 HTML_DOCS+=( "${dir}/_build/html/." )
20 }
21
22 +# @FUNCTION: epytest
23 +# @USAGE: [<args>...]
24 +# @DESCRIPTION:
25 +# Run pytest, passing the standard set of pytest options, followed
26 +# by user-specified options.
27 +#
28 +# This command dies on failure and respects nonfatal in EAPIs supporting
29 +# nonfatal die.
30 +epytest() {
31 + debug-print-function ${FUNCNAME} "${@}"
32 +
33 + [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
34 +
35 + local die_args=()
36 + [[ ${EAPI} != [45] ]] && die_args+=( -n )
37 +
38 + set -- "${EPYTHON}" -m pytest -vv "${@}"
39 +
40 + echo "${@}" >&2
41 + "${@}" || die "${die_args[@]}" "pytest failed with ${EPYTHON}"
42 + return ${?}
43 +}
44 +
45 # -- python.eclass functions --
46
47 _python_check_dead_variables() {
48 --
49 2.30.1

Replies