Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 5464a4c

Browse files
committed
Ensure --dist=loadscope is used when running pytest
The loadscope setting is required for parallel execution of our system tests using pytest. To ensure it's always used, place it in pytest.ini. This has a slight downside that pytest-xdist must still be installed even when attempting to execute tests with pytest sequentially.
1 parent cc674ff commit 5464a4c

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

bin/tests/system/README

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ Issuing plain `pytest` command without any argument will execute all tests
9797
sequenatially. To execute them in parallel, ensure you have pytest-xdist
9898
installed and run:
9999

100-
pytest --dist loadscope -n <number-of-workers>
101-
102-
It is vital to provide the `--dist loadscope` option when running the tests in
103-
parallel to ensure tests from a single module are executed from the same
104-
thread. Otherwise, there's a risk of port contention and inefficient use of
105-
resources.
100+
pytest -n <number-of-workers>
106101

107102

108103
Running the System Tests Using the Legacy Runner
@@ -706,9 +701,10 @@ Pytest-xdist is used for executing pytest test cases in parallel using the `-n
706701
N_WORKERS` option. By default, xdist will distribute any test case to any
707702
worker, which would lead to the issue described above. Therefore, it is vital
708703
to use the `--dist loadscope` option which ensures that test cases within the
709-
same (module) scope will be handled by the same worker.
704+
same (module) scope will be handled by the same worker. This option has been
705+
added to pytest.ini so it doesn't need to be specified on the command line.
710706

711-
$ pytest -n 4 --dist loadscope
707+
$ pytest -n 4
712708

713709
Test selection
714710
---

bin/tests/system/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# information regarding copyright ownership.
1111

1212
[pytest]
13-
addopts = --tb=short -rA
13+
addopts = --tb=short -rA --dist loadscope
1414
log_format = %(asctime)s %(levelname)s:%(name)s %(message)s
1515
log_date_format = %Y-%m-%d %H:%M:%S
1616
log_cli = 1

bin/tests/system/run.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def into_pytest_args(in_args):
2828
if in_args.expression is None:
2929
# running all tests - execute in parallel
3030
args.extend(["-n", "4"])
31-
args.extend(["--dist", "loadscope"])
3231
else:
3332
args.extend(["-k", in_args.expression])
3433
if in_args.noclean:
@@ -48,7 +47,7 @@ def main():
4847
"Using pytest system test runner\n\n"
4948
'Please consider invoking "pytest" directly for more control:\n'
5049
" single test: pytest -k dns64\n"
51-
" parallel tests: pytest -n 4 --dist loadscope\n\n"
50+
" parallel tests: pytest -n 4\n\n"
5251
"Alternately, use ./legacy.run.sh for the legacy system test runner.\n"
5352
)
5453

0 commit comments

Comments
 (0)