From e886f3fec8bb67f84ccf8184ce8c4e5d448f95c9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 15 May 2026 23:42:21 +0000 Subject: [PATCH] fix(claude_code/conftest): allow xdist controller to merge worker shards The previous early-return guard in pytest_sessionfinish exited before the merge step for the xdist controller process: the controller never runs tests itself (so _COLLECTOR.items is empty) and is not detected as a worker (it has no workerinput), so the guard always tripped. Worker shards were written but no process ever produced the canonical compat-results.json. Also check for shards on disk so the controller still proceeds to merge them under pytest -n auto. Co-authored-by: Yassin Kortam --- tests/claude_code/conftest.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/claude_code/conftest.py b/tests/claude_code/conftest.py index 91d7447d026..0d2593b99e4 100644 --- a/tests/claude_code/conftest.py +++ b/tests/claude_code/conftest.py @@ -419,11 +419,18 @@ def pytest_sessionfinish(session, exitstatus): unit-test trees (e.g. `_driver_unit_tests/`). Writing an empty artifact would silently overwrite a real artifact from a prior compat-test run on the same checkout. + + The xdist controller hits this hook with `_COLLECTOR.items` empty + (it never executes tests itself) and `_is_xdist_worker` False, so + we additionally allow the merge step to run when worker shards + are already on disk — otherwise the canonical artifact would + never be produced under `pytest -n auto`. """ - if not _COLLECTOR.items and not _is_xdist_worker(session): - return artifact_path = Path(os.environ.get(RESULTS_ARTIFACT_ENV) or DEFAULT_ARTIFACT_PATH) shard_dir = _shard_dir(artifact_path) + has_worker_shards = shard_dir.is_dir() and any(shard_dir.glob("*.json")) + if not _COLLECTOR.items and not _is_xdist_worker(session) and not has_worker_shards: + return shard_dir.mkdir(parents=True, exist_ok=True) worker_id = _xdist_worker_id(session) or "main"