[PATCH 1/1] pytest: default to --dist worksteal when possible

1 view
Skip to first unread message

Rob Browning

unread,
May 26, 2024, 5:47:04 PMMay 26
to bup-...@googlegroups.com
Default to worksteal if the version's new enough since it claims, and
appears, to handle test sets with more widely varying run times
better.

Move the xdist detection and other pytest default argument selection
to python. This both puts it all in one place, and avoids extra
python invocations testing for suitability. As part of that, just
have ./pytest drop xdist options (i.e. -n) when it's not available.

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---

Pushed to main.

GNUmakefile | 6 +-----
pytest | 40 +++++++++++++++++++++++++++++++++++-----
pytest.ini | 2 ++
3 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/GNUmakefile b/GNUmakefile
index a9b3e0316..cf33216b8 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -216,11 +216,7 @@ lint: dev/bup-exec dev/bup-python
test: all test/tmp dev/python lint
! bup version # Ensure we can't test the local bup (cf. dev/shadow-bin)
./bup features
- if test yes = "$$(dev/python -c 'import xdist; print("yes")' 2>/dev/null)"; then \
- (set -x; ./pytest $(xdist_opt);) \
- else \
- (set -x; ./pytest;) \
- fi
+ ./pytest $(xdist_opt)

stupid:
PATH=/bin:/usr/bin $(MAKE) test
diff --git a/pytest b/pytest
index d64d766aa..64b816e83 100755
--- a/pytest
+++ b/pytest
@@ -1,11 +1,41 @@
#!/bin/sh
-
-# Changes here might also be appropriate for ./pylint
-
+"""": # -*-python-*-
set -eu

+# Changes here might also be appropriate for ./pylint
script_home="$(cd "$(dirname "$0")" && pwd -P)"
testlibdir="$script_home/test/lib"
-
export PYTHONPATH="$testlibdir${PYTHONPATH:+:$PYTHONPATH}"
-exec dev/bup-python -m pytest -v -m 'not release' "$@"
+
+exec dev/bup-python "$0" ${1+"$@"}
+"""
+
+import pytest, shlex, sys
+
+argv = ['-v', '-m', 'not release']
+
+## Drop all xdist related opts if xdist isn't available. Otherwise
+## default to worksteal if the version's new enough since it claims,
+## and appears, to handle test sets with more widely varying run times
+## better.
+
+try:
+ import xdist
+ xdist_ver = xdist.__version__.split('.')
+ if xdist_ver >= ['3', '2', '1']: # #884: Fixed hang in worksteal scheduler
+ argv.extend(('--dist', 'worksteal'))
+ argv.extend(sys.argv[1:])
+except ModuleNotFoundError: # delete all -n opts
+ i = 1
+ while i < len(sys.argv):
+ arg = sys.argv[i]
+ if arg == '-n':
+ i += 2
+ elif arg.startswith('-n'):
+ i += 1
+ else:
+ argv.append(sys.argv[i])
+ i += 1
+
+print(shlex.join(['pytest'] + argv), file=sys.stderr)
+pytest.main(args=argv)
diff --git a/pytest.ini b/pytest.ini
index 1ba300b67..bf33c478d 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,6 +1,8 @@

[pytest]

+# See ./pytest for default arguments (instead of addopts)
+
testpaths = test/int test/ext

markers =
--
2.43.0

Reply all
Reply to author
Forward
0 new messages