You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(tests): a nested in-process pytest run evicts numpy from sys.modules, so a later test in the same worker fails to import it #1807
priority/p0-criticalPriority P0: a release blocker or a critical defectscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnerssource/agentFiled by an agenttype/bugType bug: the code does not do what it must
tests/test_ai_subcommands_rag.py::test_try_retrieve_rag_context_success fails in the pre-push gate whenever its xdist worker has earlier run tests/test_ai_test_gen.py::test_test_gen_emits_failing_scaffolds_without_presence_assertions. It blocked the push of #1805 three times (gate runs of 4m41s and 2m49s failed; other runs of the same tree passed, because which worker gets which test varies). The release branch's gate is red whenever the two land on one worker.
Cause
The test_ai_test_gen.py test passes -o addopts= to pytester.runpytest_inprocess, which drops the repository's -p no:randomly. The nested session therefore loads pytest-randomly, which imports numpy. When the test ends, pytester restores sys.modules to the snapshot it took at the start, so numpy leaves sys.modules while its C extension stays loaded in the process. numpy cannot initialise twice: the next import of it in that worker raises ImportError: cannot load module more than once per process.
The RAG test is where it shows. _try_retrieve_rag_context imports qdrant_client lazily through count_points, which imports numpy, and its except Exception: pass turns the ImportError into None, so the assertion reports None == '<rag_context>mock content</rag_context>' and nothing names the cause. Any later test that first-imports numpy in that worker fails the same way.
Evidence
Serial, one process: pytest -n 0 tests/test_ai_test_gen.py tests/test_ai_subcommands_rag.py::test_try_retrieve_rag_context_success fails, deterministically. The RAG test alone, and after test_ci_repeat.py, tests/invariants/test_hermetic_floor.py or test_isolation_tripwire.py, passes.
A temporary log of the swallowed exception in a gate run showed ImportError('cannot load module more than once per process') raised from numpy/_core/multiarray.py while qdrant.py's lazy __getattr__ imported qdrant_client.http.models.
test_ci_repeat.py also runs a nested session with pytest-randomly, but its fixture imports numpy before the nested run, so the snapshot already holds it.
Proposed remedy
Give the nested run in test_ai_test_gen.py the same -p no:randomly the repository's addopts gives every session, and make the test assert that the nested run leaves numpy's presence in sys.modules as it found it, so the next nested run that loads a numpy-importing plugin fails in its own test, not in an unrelated one.
priority/p0-criticalPriority P0: a release blocker or a critical defectscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnerssource/agentFiled by an agenttype/bugType bug: the code does not do what it must
Activity
fix(tests): a nested pytest run no longer leaves its worker unable to…
dan-petty commentedon Oct 21, 2026
What changed
#1808, merged into
release/v0.2.39as b200a02.3 file(s) changed.
How it was verified
Check runs at 18ea699:
Acceptance Criteria of
docs/agent/tasks/task-1807-nested-pytest-numpy.md:No Acceptance Criteria section.
feat(release): v0.2.39 (#1947)