Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o, Joonas Niilola <juippis@g.o>
Subject: Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing
Date: Tue, 05 Nov 2019 06:53:34
Message-Id: 68849414-489E-4CDB-B3B8-C136320B8E1C@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 1/4] distutils-r1.eclass: Add distutils_enable_tests to ease testing by Joonas Niilola
1 Dnia November 5, 2019 5:35:48 AM UTC, Joonas Niilola <juippis@g.o> napisał(a):
2 >
3 >Beautiful work, but is there a way to integrate "esetup.py test" into
4 >this as well?.
5
6 Not sure, would use some research for that. The main question is what test runners (deps) are commonly used. I'd like to avoid people mistakenly assuming that correct deps have been added for it.
7
8 >
9 >
10 >-- juippis
11 >
12 >
13 >On 11/4/19 11:00 PM, Michał Górny wrote:
14 >> Add a helpful function to handle adding common stuff for the most
15 >common
16 >> test runners.
17 >>
18 >> Signed-off-by: Michał Górny <mgorny@g.o>
19 >> ---
20 >> eclass/distutils-r1.eclass | 60
21 >++++++++++++++++++++++++++++++++++++++
22 >> 1 file changed, 60 insertions(+)
23 >>
24 >> Example ebuild use sent in replies.
25 >>
26 >> diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
27 >> index d3eb8f22ead2..2edffdb2d7c5 100644
28 >> --- a/eclass/distutils-r1.eclass
29 >> +++ b/eclass/distutils-r1.eclass
30 >> @@ -232,6 +232,66 @@ fi
31 >> # }
32 >> # @CODE
33 >>
34 >> +# @FUNCTION: distutils_enable_tests
35 >> +# @USAGE: <test-runner>
36 >> +# @DESCRIPTION:
37 >> +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests
38 >> +# with the specified test runner. Also copies the current value
39 >> +# of RDEPEND to test?-BDEPEND. The test-runner argument must be one
40 >of:
41 >> +#
42 >> +# - nose: nosetests (dev-python/nose)
43 >> +# - pytest: dev-python/pytest
44 >> +# - unittest: for built-in Python unittest module
45 >> +#
46 >> +# This function is meant as a helper for common use cases, and it
47 >only
48 >> +# takes care of basic setup. You still need to list additional test
49 >> +# dependencies manually. If you have uncommon use case, you should
50 >> +# not use it and instead enable tests manually.
51 >> +#
52 >> +# This function must be called in global scope, after RDEPEND has
53 >been
54 >> +# declared. Take care not to overwrite the variables set by it.
55 >> +distutils_enable_tests() {
56 >> + debug-print-function ${FUNCNAME} "${@}"
57 >> + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument:
58 >test-runner"
59 >> +
60 >> + [[ ${EAPI} == [56] ]] && local BDEPEND
61 >> +
62 >> + IUSE+=" test"
63 >> + RESTRICT+=" !test? ( test )"
64 >> + BDEPEND+=" test? ("
65 >> +
66 >> + case ${1} in
67 >> + nose)
68 >> + BDEPEND+=" dev-python/nose[${PYTHON_USEDEP}]"
69 >> + python_test() {
70 >> + nosetests -v || die "Tests fail with ${EPYTHON}"
71 >> + }
72 >> + ;;
73 >> + pytest)
74 >> + BDEPEND+=" dev-python/pytest[${PYTHON_USEDEP}]"
75 >> + python_test() {
76 >> + pytest -vv || die "Tests fail with ${EPYTHON}"
77 >> + }
78 >> + ;;
79 >> + unittest)
80 >> + python_test() {
81 >> + "${EPYTHON}" -m unittest discover -v ||
82 >> + die "Tests fail with ${EPYTHON}"
83 >> + }
84 >> + ;;
85 >> + *)
86 >> + die "${FUNCNAME}: unsupported argument: ${1}"
87 >> + esac
88 >> +
89 >> + BDEPEND+=" ${RDEPEND} )"
90 >> +
91 >> + [[ ${EAPI} == [56] ]] && DEPEND+=" ${BDEPEND}"
92 >> +
93 >> + # we need to ensure successful return in case we're called last,
94 >> + # otherwise Portage may wrongly assume sourcing failed
95 >> + return 0
96 >> +}
97 >> +
98 >> # @FUNCTION: esetup.py
99 >> # @USAGE: [<args>...]
100 >> # @DESCRIPTION:
101
102
103 --
104 Best regards,
105 Michał Górny