summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-11-03 20:13:31 +0100
committerMichał Górny <mgorny@gentoo.org>2023-11-07 06:29:06 +0100
commit186cdb9d71af03645861ff0cc08ded5eff5fd0c0 (patch)
tree75b6e157e8b4f8c0a302adcc58ebc8848496fb24 /eclass
parentdistutils-r1.eclass: Refactor d_e_t to permit multiple test packages (diff)
downloadgentoo-186cdb9d71af03645861ff0cc08ded5eff5fd0c0.tar.gz
gentoo-186cdb9d71af03645861ff0cc08ded5eff5fd0c0.tar.bz2
gentoo-186cdb9d71af03645861ff0cc08ded5eff5fd0c0.zip
python-utils-r1.eclass: Add EPYTEST_XDIST for epytest
Add an `EPYTEST_XDIST` variable that can be used to enable running the test suite in parallel via the dev-python/pytest-xdist plugin. This also includes user-facing `EPYTEST_JOBS` to control the job count independently of `MAKEOPTS`. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/python-utils-r1.eclass29
1 files changed, 29 insertions, 0 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 4a538f9942f6..48963728cc2f 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1307,6 +1307,19 @@ _python_check_occluded_packages() {
# parameter, when calling epytest. The listed files will be entirely
# skipped from test collection.
+# @ECLASS_VARIABLE: EPYTEST_XDIST
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, enables running tests in parallel
+# via pytest-xdist plugin.
+
+# @ECLASS_VARIABLE: EPYTEST_JOBS
+# @USER_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Specifies the number of jobs for parallel (pytest-xdist) test runs.
+# When unset, defaults to -j from MAKEOPTS, or the current nproc.
+
# @FUNCTION: epytest
# @USAGE: [<args>...]
# @DESCRIPTION:
@@ -1371,6 +1384,22 @@ epytest() {
-p no:plus
-p no:tavern
)
+
+ if [[ ${EPYTEST_XDIST} ]]; then
+ local jobs=${EPYTEST_JOBS:-$(makeopts_jobs)}
+ if [[ ${jobs} -gt 1 ]]; then
+ args+=(
+ # explicitly enable the plugin, in case the ebuild was using
+ # PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
+ -p xdist
+ -n "${jobs}"
+ # worksteal ensures that workers don't end up idle when heavy
+ # jobs are unevenly distributed
+ --dist=worksteal
+ )
+ fi
+ fi
+
local x
for x in "${EPYTEST_DESELECT[@]}"; do
args+=( --deselect "${x}" )