Skip to content

Parity divergences & upstream fixes

A catalogue of every reason a public suite diverges from exact parity in the corpus, the upstream root cause, and the concrete change the upstream project could make to remove it. These are not rstest bugs, but some are adoption blockers: each is either a deliberate rstest design choice (vendoring), an upstream test that isn't deterministic, or an upstream test that isn't parallel-safe. The corpus uses the strictest possible metric (exact nodeid + per-phase outcome), so anything non-deterministic surfaces here rather than being silently normalized away.

Which ones block a parallel run. Most entries cost a test or two of parity and the suite still runs at -n ≥ 2. Two stop the parallel run until upstream changes, so the suite runs at -n 0:

  • Non-deterministic nodeids (§2, pydantic): workers collect different ids, so rstest refuses to dispatch.
  • Real OS-resource contention (§7, httpx): a session fixture binds a fixed port on every worker.

The classes, by what actually differs:

Class What differs Suites Upstream fix
Self-referential nodeid the nodeid requests, pydantic don't parametrize on runtime paths
Non-deterministic nodeid the nodeid pydantic stable parametrize ids
Run-dependent nodeid the nodeid (marshmallow, arrow: now resolved) stable parametrize ids
Isolation defect the outcome typer reset global state per test
Exact assert on a fuzzy value the outcome rich assert the tolerant set
Wall-clock deadline the outcome urllib3, anyio, django-allauth mock the clock
Real OS resource the outcome werkzeug, httpx bind ephemeral / mark serial
Plugin controller-hook gating (was a crash) pytest-retry, pytest-rerunfailures (rstest-side, fixed)
Order-dependent serial baseline the outcome (baseline side) sqlalchemy isolate the order-dependent tests
Leaked-resource warning attribution the outcome aiohttp close sockets in the test that opens them

1. Self-referential nodeids

Outcome parity is 100%; the test passes in both runners. What differs is the nodeid string, because the test parametrizes on a value that names the running pytest, and rstest runs a vendored pytest (so it can pin byte-exact semantics independent of the installed version).

requests: tests/test_utils.py::TestExtractZippedPaths::test_unzipped_paths_unchanged

@pytest.mark.parametrize("path", ("/", __file__, pytest.__file__, "/etc/invalid/location"))
def test_unzipped_paths_unchanged(self, path):
    assert path == extract_zipped_paths(path)

pytest.__file__ is baked into the id. Baseline → …/site-packages/pytest/__init__.py; rstest → …/rstest_worker/_vendor/pytest/__init__.py. One id can't pair → 1 missing + 1 extra.

pydantic: tests/test_docs.py (the sys.path case)

Same family: an id derived from sys.path, whose worker-side entry points at the vendored core.

Upstream fix: don't embed a runtime path in a parametrize id. Use a stable literal id and pass the dynamic value through the body, or ids=:

@pytest.mark.parametrize("path", [("self", __file__), ("pytest", None)], ids=lambda p: p[0])
def test_unzipped_paths_unchanged(self, path):
    name, value = path
    value = value or pytest.__file__
    assert value == extract_zipped_paths(value)

rstest side: none needed; this is intended vendoring (see compatibility). It is a nodeid difference, not a behavior difference.


2. Non-deterministic nodeids (memory addresses, reprs)

pydantic: tests/pydantic_core/**

Several parametrize ids embed values that differ between any two Python processes:

test_complex_with_special_methods[<…ComplexWithIndex object at 0x10ae4e660>-(10+0j)]
test_tuple_var_len_kwargs[…<generator object infinite_generator at 0x10cdbd840>…]
test_any_python[MyModel({… SchemaSerializer(… class: Py(0x0000000a28267810) …)})…]

The 0x… addresses and object reprs change every run. Because full-collect dispatch is index-based (each worker must agree on the ordered id list), these per-process ids make workers' collection hashes diverge and rstest refuses to dispatch ("workers collected different test sets"): pydantic must run at -n 0.

Upstream fix: give these parametrize cases stable ids=. The values under test are fine; only their default string id (which falls back to repr(), hence the address) is unstable:

@pytest.mark.parametrize("case", CASES, ids=[c.name for c in CASES])

rstest side: -n 0. (--collect lazy also fails here for an unrelated reason, rc=4.)


3. Run-dependent nodeids: now() (resolved)

marshmallow, arrow

A few parametrize ids embed datetime.now(). These differ between the baseline run and the rstest run, but are positionally stable across workers within a run (every worker evaluates them at the same collection position). marshmallow's ids have one-second resolution and all workers collect within the same second, so the id strings match and the collection hash check passes. Ids that differ between workers (sub-second resolution, or a collection that straddles a second) fail that check and rstest refuses to dispatch; there is no automatic -n 0 fallback.

  • marshmallow runs at full -n auto at 100%: the hashes match and the renamed ids pair 1:1 positionally. (--collect lazy breaks this: its file-affine reorder destroys the positional pairing → 99.66%.)
  • arrow uses --collect lazy (one worker per file, no cross-worker hash compare) and is 100%.

Upstream fix (still worthwhile): ids derived from wall-clock are fragile; pin them. freeze_time the parametrize source, or give explicit ids=. It removes the dependence on collection-order stability entirely.


4. Isolation defect: leaked global state

typer: tests/test_callback_warning.py::test_warns_when_callback_is_not_supported

Passes alone, passes as a file, passes serially; fails only under -n auto. It asserts pytest.warns(...); when a co-located sibling runs first in the same worker process, leftover process warnings state makes the assertion miss. This is a real isolation weakness surfaced (not caused) by parallelism: any parallel runner co-locates differently than serial collection order.

Upstream fix: make the test independent of prior warnings state, reset the registry inside the test, or use a fixture:

@pytest.fixture(autouse=True)
def _clean_warnings():
    import warnings

    with warnings.catch_warnings():
        warnings.resetwarnings()
        yield

rstest side: -n 4 lowers the co-location odds (→ ~99.93%, intermittent), but only the upstream reset removes it. rstest migrate-check bisects and names the polluting sibling automatically.


5. Exact assert on a fuzzy value

rich: tests/test_syntax.py::test_syntax_guess_lexer

assert Syntax.guess_lexer("banana.html", "<%= @foo %>") == "rhtml"
assert Syntax.guess_lexer("banana.html", "{{something|filter:3}}") == "html+django"

Pygments scores several lexers equally for ambiguous .html content and breaks the tie by registry enumeration order, which shifts when extra lexer plugins are installed or when prior tests populate pygments' lazy cache in a different order. Flakes ~1 in 5 full-suite runs under plain sequential pytest: not an rstest effect. On an unlucky run the baseline and rstest disagree on this one test → ~99.8%.

The maintainers already know: the sibling test_traceback.py::test_guess_lexer_yaml_j2 asserts in ("text", "YAML+Jinja"), tolerating both outcomes. The syntax copy was never hardened the same way.

Upstream fix: assert the tolerant set, mirroring the traceback test:

assert Syntax.guess_lexer("banana.html", "<%= @foo %>") in ("rhtml", "html+php", "html")

rstest side: none; both runners are affected equally.


6. Wall-clock deadline asserts

These assert on elapsed time or a time window. They pass at low concurrency and miss the deadline when the machine is oversubscribed: under any parallel runner. Not ordering, not isolation: load.

urllib3: test/test_wait.py::test_eintr

signal.setitimer(signal.ITIMER_REAL, 0.1, 0.1)
wfs(a, read=True, timeout=1)
assert 0.9 < dur < 3  # hard upper bound

The < 3 upper bound breaks under CPU saturation.

anyio: subprocess-cancellation tests

Spawn a subprocess, cancel it, assert termination within a deadline.

django-allauth: rate-limit window tests

"N attempts within T seconds → blocked"; the window arithmetic drifts under load.

Upstream fix: mock the clock instead of asserting on real elapsed time (freezegun, a fake time.monotonic, or assert only the lower bound / behavioral outcome, never a tight upper bound).

rstest side: -n 4 for headroom; @pytest.mark.serial for the worst; or --reruns as a visible stopgap.


7. Real OS-resource contention

werkzeug: tests/test_serving.py::test_server[unix socket]

Boots a real dev-server subprocess on a unix socket and connects. Parallel-unsafe and flaky under any runner (it fails even serial/alone in some environments): on a given run baseline and rstest can disagree → ~99.9%.

Upstream fix: @pytest.mark.xdist_group("dev_server") (or rstest's @pytest.mark.serial) to keep all dev-server tests off concurrent workers, and a startup/connect retry instead of a fixed deadline.

httpx: the session server fixture

@pytest.fixture(scope="session")
def server():
    config = Config(app=app, lifespan="off", loop="asyncio")  # uvicorn default port 8000
    ...

Session scope is per worker, so every worker that touches it binds the same fixed port 8000 → clash/hang. The fixture is used across 9 files, so --dist loadfile can't confine it and there are no xdist_group markers for --dist loadgroup. Pinned -n 0.

Upstream fix: bind an ephemeral port (port=0, read back the assigned port), the standard xdist-safe pattern. Then the fixture duplicates safely per worker and httpx runs fully parallel.


8. Plugin controller-hook gating (rstest-side, fixed)

Both plugins expect a key that only pytest-xdist's controller sets, and crashed with KeyError at -n ≥ 2 until rstest handled them. No upstream change is required.

  • pytest-retry (server_port, langgraph checkpoint-sqlite): each worker self-provisions its own report server, with or without pytest-xdist installed. How: xdist hooks.
  • pytest-rerunfailures (sock_port): unregistered inside pool workers; rstest's native --reruns take over. How: xdist hooks.

9. Order-dependent serial baseline

sqlalchemy: IMV / RETURNING tests

The corpus runs SQLAlchemy (about 25,300 tests) at -n auto and measures about 99.96% parity (corpus/bench-results/2026-09-26-sqlalchemy-parity.json). The gap is 9 IMV/RETURNING tests (test_insert_exec.py IMVSentinelTest, test_suite.py ReturningTest) that skip in the serial pytest baseline, where their outcome depends on what ran before them in the full serial order, and pass under any parallel runner. Real pytest-xdist -n 2 passes them too, so this is a serial-versus-parallel artifact in the baseline, not an rstest or follower-database defect.

Upstream fix: make these tests independent of full-suite order, so the serial run no longer skips them.


10. Leaked-resource warning attribution

aiohttp: a different few tests per run

aiohttp runs with warnings as errors, and some of its tests leak a socket. The leak is only noticed when the garbage collector finalizes the socket, which raises an unraisable ResourceWarning inside whatever test is running at that moment, and that test fails. In serial order the collection point is stable, so the baseline is clean; under any parallel runner the tests around it change and the failure lands somewhere else. The 2026-11-10 cold-cache benchmark runs measured 99.91-99.98% parity (1 to 4 mismatched tests per run; the warm runs that day measured 100%; see Benchmarks). In an earlier sample (2026-09-26, -n 8), rstest failed test_connector.py::test_tcp_connector_do_not_raise_connector_ssl_error[domain name] and test_formdata.py::test_formdata_field_name_is_quoted with ResourceWarning: unclosed <socket.socket ...>, plus one test_web_functional.py::test_app_max_client_size_form 500; pytest-xdist at the same -n failed two other tests, one of them a pure cookie-parsing unit test (test_cookie_helpers.py::test_unquote_basic) with no I/O of its own. The failing test is the victim, not the cause.

Upstream fix: close every socket, session and transport in the test (or fixture) that opens it, so nothing is left for the garbage collector.

rstest side: --fail-on-leak and the --doctor leak report name the test that leaves a file descriptor open after its teardown, which is the one to fix.


Summary: the upstream-fix shortlist

For a suite maintainer who wants exact parallel parity:

  1. Never put a runtime path, memory address, or now() in a parametrize id. Use ids= with stable labels. (requests, pydantic, marshmallow, arrow)
  2. Reset mutated global state per test: warnings filters, registries, env, sys.path. (typer)
  3. Assert tolerant sets, not exact values, for inherently fuzzy results. (rich)
  4. Mock the clock; never assert a tight upper time bound. (urllib3, anyio, django-allauth)
  5. Bind ephemeral ports / mark serial for fixed OS resources. (httpx, werkzeug)
  6. Close what you open. A leaked socket fails an innocent test when it is garbage-collected under warnings-as-errors. (aiohttp)