test: replace manual state-reset fixtures with pytest-isolate#28956
test: replace manual state-reset fixtures with pytest-isolate#28956ethernet8023 wants to merge 1 commit into
Conversation
🚨 CRITICAL Supply Chain Risk DetectedThis PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging. 🚨 CRITICAL: Install-hook file added or modifiedThese files can execute code during package installation or interpreter startup. Files: Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting. |
|
🔎 Lint report:
|
87ba526 to
8aef067
Compare
🚨 CRITICAL Supply Chain Risk DetectedThis PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging. 🚨 CRITICAL: Install-hook file added or modifiedThese files can execute code during package installation or interpreter startup. Files: Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting. |
Each test now runs in a forked subprocess (--isolate), so module-level dicts/sets/ContextVars can no longer leak between tests on the same xdist worker. This eliminates the need for: - _reset_module_state autouse fixture (~120 lines clearing approval state, gateway session ContextVars, terminal env caches, etc.) - _enforce_test_timeout + _timeout_handler (SIGALRM-based 30s timeout) - _reset_tool_registry_caches (registry + tool defs cache invalidation) With isolation in place, bump the xdist worker cap from 4 to auto in scripts/run_tests.sh and pyproject.toml addopts. Developers on big machines finally get parallelism proportional to their core count.
8aef067 to
48a1fa9
Compare
🚨 CRITICAL Supply Chain Risk DetectedThis PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging. 🚨 CRITICAL: Install-hook file added or modifiedThese files can execute code during package installation or interpreter startup. Files: Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting. |
|
Opened #28966 as a branch updated onto current |
What does this PR do?
Replaces the ~130-line manual "reset module state" machinery in tests/conftest.py with pytest-isolate, which forks each test into its ownsubprocess. This eliminates all cross-test state leakage (module-level dicts, sets, ContextVars) at the process boundary level — the old fixturewas a best-effort workaround that grew brittle as new state buckets were added.
With true isolation in place, the xdist worker cap is lifted from 4 to auto. Developers on big machines finally get parallelism proportional totheir core count without "works alone, flakes in CI" bugs.
Related Issue
Fixes #
Type of Change
Changes Made
pyproject.toml: added --isolate to pytest addopts, set isolate_timeout = "30", added pytest-isolate>=0.0.13 to dev deps
tests/conftest.py: removed _reset_module_state autouse fixture (~120 lines clearing approval state, gateway ContextVars, terminal env caches,file-ops caches, etc.), removed _enforce_test_timeout + _timeout_handler, removed _reset_tool_registry_caches: replaced by process-per-test isolation. Cleaned up unused logging, signal, tempfile imports.
scripts/run_tests.sh: bumped default WORKERS from 4 to auto, updated header comment
How to Test
python -m pytest tests/tools/test_approval.py -n 16 --tb=shortChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A