commit: 2fa29ae45ece5e6c8a7c8b944e8731f383bf101b Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Nov 28 23:45:00 2020 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Tue Dec 1 10:31:52 2020 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2fa29ae4
distutils-r1.eclass: Accept distutils_enable_tests --install Add a convenience --install option to distutils_enable_tests to call distutils_install_for_testing. Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> eclass/distutils-r1.eclass | 74 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index a0eb41e689a..5ffc91be479 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -378,7 +378,7 @@ distutils_enable_sphinx() { } # @FUNCTION: distutils_enable_tests -# @USAGE: <test-runner> +# @USAGE: [--install] <test-runner> # @DESCRIPTION: # Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests # with the specified test runner. Also copies the current value @@ -389,6 +389,10 @@ distutils_enable_sphinx() { # - setup.py: setup.py test (no deps included) # - unittest: for built-in Python unittest module # +# Additionally, if --install is passed as the first parameter, +# 'distutils_install_for_testing --via-root' is called before running +# the test suite. +# # This function is meant as a helper for common use cases, and it only # takes care of basic setup. You still need to list additional test # dependencies manually. If you have uncommon use case, you should @@ -398,33 +402,71 @@ distutils_enable_sphinx() { # declared. Take care not to overwrite the variables set by it. distutils_enable_tests() { debug-print-function ${FUNCNAME} "${@}" - [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner" + local do_install= + case ${1} in + --install) + do_install=1 + shift + ;; + esac + + [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: test-runner" local test_pkg case ${1} in nose) test_pkg=">=dev-python/nose-1.3.7-r4" - python_test() { - nosetests -v || die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + nosetests -v || die "Tests fail with ${EPYTHON}" + } + else + python_test() { + nosetests -v || die "Tests fail with ${EPYTHON}" + } + fi ;; pytest) test_pkg=">=dev-python/pytest-4.5.0" - python_test() { - pytest -vv || die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + pytest -vv || die "Tests fail with ${EPYTHON}" + } + else + python_test() { + pytest -vv || die "Tests fail with ${EPYTHON}" + } + fi ;; setup.py) - python_test() { - nonfatal esetup.py test --verbose || - die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + nonfatal esetup.py test --verbose || + die "Tests fail with ${EPYTHON}" + } + else + python_test() { + nonfatal esetup.py test --verbose || + die "Tests fail with ${EPYTHON}" + } + fi ;; unittest) - python_test() { - "${EPYTHON}" -m unittest discover -v || - die "Tests fail with ${EPYTHON}" - } + if [[ ${do_install} ]]; then + python_test() { + distutils_install_for_testing --via-root + "${EPYTHON}" -m unittest discover -v || + die "Tests fail with ${EPYTHON}" + } + else + python_test() { + "${EPYTHON}" -m unittest discover -v || + die "Tests fail with ${EPYTHON}" + } + fi ;; *) die "${FUNCNAME}: unsupported argument: ${1}"