diff options
author | V3n3RiX <venerix@redcorelinux.org> | 2019-11-18 10:15:03 +0000 |
---|---|---|
committer | V3n3RiX <venerix@redcorelinux.org> | 2019-11-18 10:15:03 +0000 |
commit | b284a3168fa91a038925d2ecf5e4791011ea5e7d (patch) | |
tree | 16fe44748708acacd909d4e2e160a09a7f6d936a /eclass/distutils-r1.eclass | |
parent | 77398e424e45d9e98c1cef3c43bdadb9d56e81ef (diff) |
gentoo resync : 18.11.2019
Diffstat (limited to 'eclass/distutils-r1.eclass')
-rw-r--r-- | eclass/distutils-r1.eclass | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index d3eb8f22ead2..e2cd076d4148 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -232,6 +232,67 @@ fi # } # @CODE +# @FUNCTION: distutils_enable_tests +# @USAGE: <test-runner> +# @DESCRIPTION: +# Set up IUSE, RESTRICT, BDEPEND and python_test() for running tests +# with the specified test runner. Also copies the current value +# of RDEPEND to test?-BDEPEND. The test-runner argument must be one of: +# +# - nose: nosetests (dev-python/nose) +# - pytest: dev-python/pytest +# - unittest: for built-in Python unittest module +# +# 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 +# not use it and instead enable tests manually. +# +# This function must be called in global scope, after RDEPEND has been +# 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 test_deps + case ${1} in + nose) + test_deps="dev-python/nose[${PYTHON_USEDEP}]" + python_test() { + nosetests -v || die "Tests fail with ${EPYTHON}" + } + ;; + pytest) + test_deps="dev-python/pytest[${PYTHON_USEDEP}]" + python_test() { + pytest -vv || die "Tests fail with ${EPYTHON}" + } + ;; + unittest) + python_test() { + "${EPYTHON}" -m unittest discover -v || + die "Tests fail with ${EPYTHON}" + } + ;; + *) + die "${FUNCNAME}: unsupported argument: ${1}" + esac + + if [[ -n ${test_deps} || -n ${RDEPEND} ]]; then + IUSE+=" test" + RESTRICT+=" !test? ( test )" + if [[ ${EAPI} == [56] ]]; then + DEPEND+=" test? ( ${test_deps} ${RDEPEND} )" + else + BDEPEND+=" test? ( ${test_deps} ${RDEPEND} )" + fi + fi + + # we need to ensure successful return in case we're called last, + # otherwise Portage may wrongly assume sourcing failed + return 0 +} + # @FUNCTION: esetup.py # @USAGE: [<args>...] # @DESCRIPTION: |