Skip to content

Pytest 9 no longer supports pytest-xdist run groups - #12715

Merged
crusaderky merged 6 commits into
dask:mainfrom
crusaderky:fix/s3-fixture-xdist
Nov 12, 2026
Merged

crusaderky merged 6 commits into
dask:mainfrom
crusaderky:fix/s3-fixture-xdist

Conversation

@crusaderky

@crusaderky crusaderky commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

dask/bytes/tests/test_s3.py and test_http.py declare

pytestmark = pytest.mark.xdist_group(name="s3")

because the modules are not concurrent-safe.

Under pytest 9, that mark is silently ignored.

Symptoms in the test job: FileNotFoundError: The specified bucket does not exist, NoSuchBucket, OSError: [Errno 39] The bucket you tried to delete is not empty, _lzma.LZMAError, and wrong bucket contents.

Fix it by making the fixtures worker-safe, so the module no longer relies on the xdist_group mark taking effect.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     25 files  ±  0       25 suites  ±0   6h 11m 40s ⏱️ - 40m 58s
 19 919 tests +  5   18 486 ✅ +  6   1 433 💤 ±0  0 ❌  - 1 
379 473 runs  +120  332 199 ✅ +115  47 274 💤 +6  0 ❌  - 1 

Results for commit 44005e2. ± Comparison against base commit b4cc5c5.

This pull request removes 52 and adds 57 tests. Note that renamed tests count towards both.
dask.bytes.tests.test_http ‑ test_bag@http
dask.bytes.tests.test_http ‑ test_errors@http
dask.bytes.tests.test_http ‑ test_fetch_range_with_headers@http
dask.bytes.tests.test_http ‑ test_files@http
dask.bytes.tests.test_http ‑ test_loc@http
dask.bytes.tests.test_http ‑ test_open_glob@http
dask.bytes.tests.test_http ‑ test_ops[99999]@http
dask.bytes.tests.test_http ‑ test_ops[None]@http
dask.bytes.tests.test_http ‑ test_ops_blocksize@http
dask.bytes.tests.test_http ‑ test_parquet@http
…
dask.bytes.tests.test_http ‑ test_bag
dask.bytes.tests.test_http ‑ test_errors
dask.bytes.tests.test_http ‑ test_fetch_range_with_headers
dask.bytes.tests.test_http ‑ test_files
dask.bytes.tests.test_http ‑ test_loc
dask.bytes.tests.test_http ‑ test_open_glob
dask.bytes.tests.test_http ‑ test_ops[99999]
dask.bytes.tests.test_http ‑ test_ops[None]
dask.bytes.tests.test_http ‑ test_ops_blocksize
dask.bytes.tests.test_http ‑ test_parquet
…
This pull request removes 9 skipped tests and adds 9 skipped tests. Note that renamed tests count towards both.
dask.bytes.tests.test_http ‑ test_bag@http
dask.bytes.tests.test_s3 ‑ test_compression[lz4-10]@s3
dask.bytes.tests.test_s3 ‑ test_compression[lz4-None]@s3
dask.bytes.tests.test_s3 ‑ test_compression[lzma-10]@s3
dask.bytes.tests.test_s3 ‑ test_compression[lzma-None]@s3
dask.bytes.tests.test_s3 ‑ test_compression[snappy-10]@s3
dask.bytes.tests.test_s3 ‑ test_compression[snappy-None]@s3
dask.bytes.tests.test_s3 ‑ test_compression[zstd-10]@s3
dask.bytes.tests.test_s3 ‑ test_compression[zstd-None]@s3
dask.bytes.tests.test_http ‑ test_bag
dask.bytes.tests.test_s3 ‑ test_compression[lz4-10]
dask.bytes.tests.test_s3 ‑ test_compression[lz4-None]
dask.bytes.tests.test_s3 ‑ test_compression[lzma-10]
dask.bytes.tests.test_s3 ‑ test_compression[lzma-None]
dask.bytes.tests.test_s3 ‑ test_compression[snappy-10]
dask.bytes.tests.test_s3 ‑ test_compression[snappy-None]
dask.bytes.tests.test_s3 ‑ test_compression[zstd-10]
dask.bytes.tests.test_s3 ‑ test_compression[zstd-None]

♻️ This comment has been updated with latest results.

@crusaderky crusaderky changed the title [unsupervised AI] Isolate the moto S3 fixture per pytest-xdist worker Pytest 9 vs. pytest-xdist on s3 tests Nov 12, 2026
pytest 9 no longer applies the xdist_group marker: xdist's worker-side
pytest_collection_modifyitems gates on config.getvalue("loadgroup"),
which is not a registered option, so the @group nodeid suffix is never
appended and --dist loadgroup silently degrades to plain load balancing.
test_s3.py then runs concurrently across workers, all sharing one moto
server on port 5555 and one bucket named "test", which produces
NoSuchBucket / FileNotFoundError / "bucket not empty" errors and
cross-contaminated bucket contents.

Derive the moto port from PYTEST_XDIST_WORKER so that every worker owns
its own S3 state, and build endpoint_uri from it. The bucket name and
the tests are unchanged. Keep the xdist_group mark, which is still
correct (and still effective on pytest 8).
pytest 9 turned `Node.nodeid` into a read-only property backed by `self._id`,
so the `item._nodeid = f"{item.nodeid}@{group}"` assignment that pytest-xdist
performs in `remote.py` became a no-op. Under pytest 9, `--dist loadgroup` now
silently ignores `pytest.mark.xdist_group`, which makes every module that relies
on it run on several workers at once.

`test_s3.py` was already hardened against that by giving each worker its own
moto server, so its mark is now dead weight above the fixtures that actually
provide the isolation; drop it.

`test_http.py` was not: every worker started `http.server` on the hardcoded
port 8999, so the second worker to start one died with "Address already in
use" and every test in it failed with `ClientConnectorError` (reproduced with
pytest 9.2.0 / xdist 3.8.0: 8 passed, 1 failed with ConnectionRefused).
Derive the port from the worker id, like the s3 module does, and drop its mark
too.

Rather than copy the port helper into a second module, move it to
`dask.utils_test` as `xdist_worker_port()` and cover it with a unit test.

Also reap the `http.server` child on teardown: `terminate()` alone left it
running, which emitted a `Popen.__del__` ResourceWarning per worker and could
keep the port bound for the next run.
@crusaderky crusaderky changed the title Pytest 9 vs. pytest-xdist on s3 tests Pytest 9 no longer supports pytest-xdist run groups Nov 12, 2026
@crusaderky
crusaderky marked this pull request as ready for review November 12, 2026 17:23
@crusaderky
crusaderky merged commit 146984d into dask:main Nov 12, 2026
29 of 32 checks passed
@crusaderky
crusaderky deleted the fix/s3-fixture-xdist branch November 12, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant