1 |
Add an eunittest helper to wrap up the common 'python -m unittest |
2 |
discover' calls, except that they are run via |
3 |
dev-python/unittest-or-fail now. This guarantees that if no tests are |
4 |
discovered the test phase fails rather than silently ignoring |
5 |
the problem. This is especially helpful since it saves the developer |
6 |
from having to inspect test phase logs. |
7 |
|
8 |
Signed-off-by: Michał Górny <mgorny@g.o> |
9 |
--- |
10 |
eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++ |
11 |
1 file changed, 23 insertions(+) |
12 |
|
13 |
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass |
14 |
index 3036148b8383..d0bfb7819059 100644 |
15 |
--- a/eclass/python-utils-r1.eclass |
16 |
+++ b/eclass/python-utils-r1.eclass |
17 |
@@ -1299,5 +1299,28 @@ epytest() { |
18 |
return ${?} |
19 |
} |
20 |
|
21 |
+# @FUNCTION: eunittest |
22 |
+# @USAGE: [<args>...] |
23 |
+# @DESCRIPTION: |
24 |
+# Run unit tests using dev-python/unittest-or-fail, passing the standard |
25 |
+# set of options, followed by user-specified options. |
26 |
+# |
27 |
+# This command dies on failure and respects nonfatal in EAPIs supporting |
28 |
+# nonfatal die. |
29 |
+eunittest() { |
30 |
+ debug-print-function ${FUNCNAME} "${@}" |
31 |
+ |
32 |
+ [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context" |
33 |
+ |
34 |
+ local die_args=() |
35 |
+ [[ ${EAPI} != [45] ]] && die_args+=( -n ) |
36 |
+ |
37 |
+ set -- "${EPYTHON}" -m unittest_or_fail discover -v "${@}" |
38 |
+ |
39 |
+ echo "${@}" >&2 |
40 |
+ "${@}" || die "${die_args[@]}" "Tests failed with ${EPYTHON}" |
41 |
+ return ${?} |
42 |
+} |
43 |
+ |
44 |
_PYTHON_UTILS_R1=1 |
45 |
fi |
46 |
-- |
47 |
2.30.2 |