1 |
Use a common distutils-r1_python_test function to simplify handling |
2 |
different test scenarios. This avoids code duplication due to defining |
3 |
a lot of python_test() variants, as well as it makes it possible for |
4 |
overriden python_test() to call the base implementation provided |
5 |
by distutils_enable_tests. |
6 |
|
7 |
Signed-off-by: Michał Górny <mgorny@g.o> |
8 |
--- |
9 |
eclass/distutils-r1.eclass | 93 +++++++++++++++++++------------------- |
10 |
1 file changed, 47 insertions(+), 46 deletions(-) |
11 |
|
12 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
13 |
index f5b151d4b8e2..0e543412f645 100644 |
14 |
--- a/eclass/distutils-r1.eclass |
15 |
+++ b/eclass/distutils-r1.eclass |
16 |
@@ -406,10 +406,10 @@ distutils_enable_sphinx() { |
17 |
distutils_enable_tests() { |
18 |
debug-print-function ${FUNCNAME} "${@}" |
19 |
|
20 |
- local do_install= |
21 |
+ _DISTUTILS_TEST_INSTALL= |
22 |
case ${1} in |
23 |
--install) |
24 |
- do_install=1 |
25 |
+ _DISTUTILS_TEST_INSTALL=1 |
26 |
shift |
27 |
;; |
28 |
esac |
29 |
@@ -419,62 +419,21 @@ distutils_enable_tests() { |
30 |
case ${1} in |
31 |
nose) |
32 |
test_pkg=">=dev-python/nose-1.3.7-r4" |
33 |
- if [[ ${do_install} ]]; then |
34 |
- python_test() { |
35 |
- distutils_install_for_testing --via-root |
36 |
- nosetests -v || die "Tests fail with ${EPYTHON}" |
37 |
- } |
38 |
- else |
39 |
- python_test() { |
40 |
- nosetests -v || die "Tests fail with ${EPYTHON}" |
41 |
- } |
42 |
- fi |
43 |
;; |
44 |
pytest) |
45 |
test_pkg=">=dev-python/pytest-4.5.0" |
46 |
- if [[ ${do_install} ]]; then |
47 |
- python_test() { |
48 |
- distutils_install_for_testing --via-root |
49 |
- epytest |
50 |
- } |
51 |
- else |
52 |
- python_test() { |
53 |
- epytest |
54 |
- } |
55 |
- fi |
56 |
;; |
57 |
setup.py) |
58 |
- if [[ ${do_install} ]]; then |
59 |
- python_test() { |
60 |
- distutils_install_for_testing --via-root |
61 |
- nonfatal esetup.py test --verbose || |
62 |
- die "Tests fail with ${EPYTHON}" |
63 |
- } |
64 |
- else |
65 |
- python_test() { |
66 |
- nonfatal esetup.py test --verbose || |
67 |
- die "Tests fail with ${EPYTHON}" |
68 |
- } |
69 |
- fi |
70 |
;; |
71 |
unittest) |
72 |
- if [[ ${do_install} ]]; then |
73 |
- python_test() { |
74 |
- distutils_install_for_testing --via-root |
75 |
- "${EPYTHON}" -m unittest discover -v || |
76 |
- die "Tests fail with ${EPYTHON}" |
77 |
- } |
78 |
- else |
79 |
- python_test() { |
80 |
- "${EPYTHON}" -m unittest discover -v || |
81 |
- die "Tests fail with ${EPYTHON}" |
82 |
- } |
83 |
- fi |
84 |
;; |
85 |
*) |
86 |
die "${FUNCNAME}: unsupported argument: ${1}" |
87 |
esac |
88 |
|
89 |
+ _DISTUTILS_TEST_RUNNER=${1} |
90 |
+ python_test() { distutils-r1_python_test; } |
91 |
+ |
92 |
local test_deps=${RDEPEND} |
93 |
if [[ -n ${test_pkg} ]]; then |
94 |
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then |
95 |
@@ -841,6 +800,48 @@ _distutils-r1_wrap_scripts() { |
96 |
fi |
97 |
} |
98 |
|
99 |
+# @FUNCTION: distutils-r1_python_test |
100 |
+# @USAGE: [additional-args...] |
101 |
+# @DESCRIPTION: |
102 |
+# The python_test() implementation used by distutils_enable_tests. |
103 |
+# Runs tests using the specified test runner, possibly installing them |
104 |
+# first. |
105 |
+# |
106 |
+# This function is used only if distutils_enable_tests is called. |
107 |
+distutils-r1_python_test() { |
108 |
+ debug-print-function ${FUNCNAME} "${@}" |
109 |
+ |
110 |
+ if [[ -z ${_DISTUTILS_TEST_RUNNER} ]]; then |
111 |
+ die "${FUNCNAME} can be only used after calling distutils_enable_tests" |
112 |
+ fi |
113 |
+ |
114 |
+ if [[ ${_DISTUTILS_TEST_INSTALL} ]]; then |
115 |
+ distutils_install_for_testing |
116 |
+ fi |
117 |
+ |
118 |
+ case ${_DISTUTILS_TEST_RUNNER} in |
119 |
+ nose) |
120 |
+ nosetests -v "${@}" |
121 |
+ ;; |
122 |
+ pytest) |
123 |
+ epytest |
124 |
+ ;; |
125 |
+ setup.py) |
126 |
+ nonfatal esetup.py test --verbose |
127 |
+ ;; |
128 |
+ unittest) |
129 |
+ "${EPYTHON}" -m unittest discover -v |
130 |
+ ;; |
131 |
+ *) |
132 |
+ die "Mis-synced test runner between ${FUNCNAME} and distutils_enable_testing" |
133 |
+ ;; |
134 |
+ esac |
135 |
+ |
136 |
+ if [[ ${?} -ne 0 ]]; then |
137 |
+ die "Tests failed with ${EPYTHON}" |
138 |
+ fi |
139 |
+} |
140 |
+ |
141 |
# @FUNCTION: distutils-r1_python_install |
142 |
# @USAGE: [additional-args...] |
143 |
# @DESCRIPTION: |
144 |
-- |
145 |
2.30.1 |