Repository navigation
Description
On pytest main, --dist=loadgroup no longer groups tests by xdist_group. Nothing fails: the tests are simply distributed as if the mark were not there.
Reproducer
test_a.py, and an identical test_b.py:
import pytest
class TestA:
@pytest.mark.xdist_group(name="xdist_group")
@pytest.mark.parametrize("i", range(5))
def test(self, i):
passpytest -n2 --dist=loadgroup -v
xdist master (eba6a44) with pytest 9.1.1 — one group, one worker:
[gw0] [ 10%] PASSED test_a.py::TestA::test[0]@xdist_group
[gw0] [ 20%] PASSED test_a.py::TestA::test[1]@xdist_group
[gw0] [ 30%] PASSED test_a.py::TestA::test[2]@xdist_group
[gw0] [ 40%] PASSED test_a.py::TestA::test[3]@xdist_group
[gw0] [ 50%] PASSED test_a.py::TestA::test[4]@xdist_group
[gw0] [ 60%] PASSED test_b.py::TestA::test[0]@xdist_group
[gw0] [ 70%] PASSED test_b.py::TestA::test[1]@xdist_group
[gw0] [ 80%] PASSED test_b.py::TestA::test[2]@xdist_group
[gw0] [ 90%] PASSED test_b.py::TestA::test[3]@xdist_group
[gw0] [100%] PASSED test_b.py::TestA::test[4]@xdist_group
The same xdist with pytest 9.2.0.dev340+g6a0de9be5 — no suffix, round-robin:
[gw1] [ 10%] PASSED test_a.py::TestA::test[1]
[gw0] [ 20%] PASSED test_a.py::TestA::test[0]
[gw1] [ 30%] PASSED test_a.py::TestA::test[3]
[gw0] [ 40%] PASSED test_a.py::TestA::test[2]
[gw0] [ 50%] PASSED test_b.py::TestA::test[0]
[gw1] [ 60%] PASSED test_a.py::TestA::test[4]
[gw0] [ 70%] PASSED test_b.py::TestA::test[1]
[gw1] [ 80%] PASSED test_b.py::TestA::test[2]
[gw1] [ 90%] PASSED test_b.py::TestA::test[4]
[gw0] [100%] PASSED test_b.py::TestA::test[3]
Cause
The group name reaches the controller as a suffix on the nodeid, written in src/xdist/remote.py:264:
item._nodeid = f"{item.nodeid}@{'_'.join(sorted(gnames))}"pytest-dev/pytest#14758 (431f3e1f5, merged 2026-09-06) replaced string nodeids with a structured NodeId. Node.nodeid is now a read-only property over self._id, so that line writes an attribute nobody reads — silently, without raising.
With no @ in the nodeid, LoadGroupScheduling._split_scope returns the nodeid itself:
if nodeid.rfind("@") > nodeid.rfind("]"):
return nodeid.split("@")[-1]
else:
return nodeidso every test becomes its own scope. That is why the tests scatter rather than falling back to module or class grouping.
For what it is worth, that pytest PR kept the public nodeid string as a backward-compatible read surface; what breaks here is our write to the private _nodeid.
Where this shows up
py311-pytestmain is red on every open PR — #1383, #1384 and #1385 (run from today) — always the same five tests: TestGroupScope::test_by_module, test_by_class, test_module_single_start, test_multiple_group_marks and test_multiple_group_order.
master still looks unaffected only because its test workflow last ran pytestmain on 2026-09-04, two days before that pytest merge.
No released pytest is affected, so nobody is broken today. When 9.2 ships, tests that need to share a worker will quietly stop doing so, which is the kind of failure that is hard to attribute from the outside.
Related
#1119 ("Loadgroup: Don't modify test nodeids any longer", Aug 2024) proposed replacing this side-channel with an explicit parameter. I have no view on whether that is the right fix now versus adapting the write — just noting that it exists and is still open.
Environment
- pytest-xdist master
eba6a44 - pytest
9.2.0.dev340+g6a0de9be5(and 9.1.1 for the comparison) - execnet 2.1.2, CPython 3.13.14, Linux
Activity
fix(ci): cap pytest below 9.2 so the shared_test_db xdist group forms…
Dev: pytest below 9.2 until a pytest-xdist release after 3.8.0, since…
CI: Pin pytest<9.2 (AMICI-dev#3501)
test: pin pytest<9.2 until xdist supports its node ids (#577)
Write HDF5 files of unit tests to `tmp_path` (Pytest fixture) (#205)
test: render each variant once, off tmpfs, with at most 4 local worke…
test: render each variant once, off tmpfs, with at most 4 local worke…
test: render each variant once, off tmpfs, with at most 4 local worke…
Tarea P.1: tests por niveles con sello, xdist y CI en paralelo (#52)
test: pin pytest below 9.2, so --dist loadgroup groups again
chore(deps): hold pytest below 9.2 to restore xdist grouping
ci: keep each test class on one worker with --dist loadscope
ci: cut Actions minutes (#48)
build(deps): hold pytest below 9.2 until pytest-xdist supports it
build(deps): bump soupsieve to 4.1 and require python >=3.11.5 (#906)
Serialise stress_heavy tests with a cross-worker file lock
build(deps): bump tornado to 6.6.1, ruff, uv image and qa actions (#918)
build(deps): bump coverage, prek, ruff, nbstripout, ci actions and uv…
Cut the nightly suite's cost: share Firefox and WebKit per worker, re…