Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
Date: Mon, 04 Nov 2019 21:00:46
Message-Id: 20191104210013.49303-1-mgorny@gentoo.org
1 Add a helpful function to handle adding common stuff for the most common
2 test runners.
3
4 Signed-off-by: Michał Górny <mgorny@g.o>
5 ---
6 eclass/distutils-r1.eclass | 60 ++++++++++++++++++++++++++++++++++++++
7 1 file changed, 60 insertions(+)
8
9 Example ebuild use sent in replies.
10
11 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
12 index d3eb8f22ead2..2edffdb2d7c5 100644
13 --- a/eclass/distutils-r1.eclass
14 +++ b/eclass/distutils-r1.eclass
15 @@ -232,6 +232,66 @@ fi
16 # }
17 # @CODE
18
19 +# @FUNCTION: distutils_enable_tests
20 +# @USAGE: <test-runner>
21 +# @DESCRIPTION:
22 +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
23 +# with the specified test runner. Also copies the current value
24 +# of RDEPEND to test?-BDEPEND. The test-runner argument must be one of:
25 +#
26 +# - nose: nosetests (dev-python/nose)
27 +# - pytest: dev-python/pytest
28 +# - unittest: for built-in Python unittest module
29 +#
30 +# This function is meant as a helper for common use cases, and it only
31 +# takes care of basic setup. You still need to list additional test
32 +# dependencies manually. If you have uncommon use case, you should
33 +# not use it and instead enable tests manually.
34 +#
35 +# This function must be called in global scope, after RDEPEND has been
36 +# declared. Take care not to overwrite the variables set by it.
37 +distutils_enable_tests() {
38 + debug-print-function ${FUNCNAME} "${@}"
39 + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner"
40 +
41 + [[ ${EAPI} == [56] ]] && local BDEPEND
42 +
43 + IUSE+=" test"
44 + RESTRICT+=" !test? ( test )"
45 + BDEPEND+=" test? ("
46 +
47 + case ${1} in
48 + nose)
49 + BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
50 + python_test() {
51 + nosetests -v || die "Tests fail with ${EPYTHON}"
52 + }
53 + ;;
54 + pytest)
55 + BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
56 + python_test() {
57 + pytest -vv || die "Tests fail with ${EPYTHON}"
58 + }
59 + ;;
60 + unittest)
61 + python_test() {
62 + "${EPYTHON}" -m unittest discover -v ||
63 + die "Tests fail with ${EPYTHON}"
64 + }
65 + ;;
66 + *)
67 + die "${FUNCNAME}: unsupported argument: ${1}"
68 + esac
69 +
70 + BDEPEND+=" ${RDEPEND} )"
71 +
72 + [[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
73 +
74 + # we need to ensure successful return in case we're called last,
75 + # otherwise Portage may wrongly assume sourcing failed
76 + return 0
77 +}
78 +
79 # @FUNCTION: esetup.py
80 # @USAGE: [<args>...]
81 # @DESCRIPTION:
82 --
83 2.23.0

Replies