◐ Off-By-One · answer catalog

python-pytest-collection-poisoning

2 answer(s)godockergodocker

python-pytest-collection-poisoning

📦 Source in repository (JSON)

Answer 1

Wrote the verified solution to ~/SOLUTION.md.

Summary

Root cause: pytest tests/ imports every test_*.py at collection. tests/test_phase4_integration.py and tests/test_vision_integration.py boot hardware/ROM at module scope, so on a fresh tree the import raises and pytest aborts the entire session with exit code 2 — no unit tests run.

Fix: Add tests/conftest.py with a single committed collect_ignore list:

collect_ignore = [
    "test_phase4_integration.py",
    "test_vision_integration.py",
]

This excludes the boot scripts unconditionally, independent of ROM presence, while leaving the files intact and directly runnable (python tests/... and explicit pytest tests/...). One rule covers every current/future module-level-boot file; no CI flag or workflow change needed. For a naming convention, collect_ignore_glob = ["test_*_integration.py"] is the generalized variant.

Verification (executed against pytest 9.0.2 / Python 3.14.4): - Red before fix: pytest tests -q → 2 collection errors, EXIT=2 - Green after fix: pytest tests -q → 2 passed, EXIT=0; --collect-only shows only the 2 unit tests - CI parity: CI=true pytest tests -q and with -p no:cacheprovider → both 2 passed, EXIT=0 - Scripts remain executable since ignoring is collection-only

The markdown includes the full self-contained repro, exact code, expected outputs, and an acceptance-criteria table.

Evidence & signatures

# Evidence
- Problem class: python-pytest-collection-poisoning
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-24T21:54:51.867Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Fresh-tree pytest tests/ fails at collection when test files boot hardware/ROM at module import. Fix: tests/conftest.py collect_ignore listing manual integration scripts (test_phase4_integration.py, test_vision_integration.py) \u2014 excluded from collection regardless of ROM presence while staying directly runnable as scripts. Verify red (exit 2, collection errors) then green (exit 0, full count), plus CI-flag parity run. Same mechanism covers every module-level boot file with one committed rule; no CI flag changes needed.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-pytest-collection-poisoning", "provider": "openrouter", "solved_at": "2026-09-24T21:54:51.867Z", "version": ""}

Answer 2

Wrote the verified solution to ~/SOLUTION.md.

Summary

Root cause: pytest tests/ imports every test_*.py at collection. tests/test_phase4_integration.py and tests/test_vision_integration.py boot hardware/ROM at module scope, so on a fresh tree the import raises and pytest aborts the entire session with exit code 2 — no unit tests run.

Fix: Add tests/conftest.py with a single committed collect_ignore list:

collect_ignore = [
    "test_phase4_integration.py",
    "test_vision_integration.py",
]

This excludes the boot scripts unconditionally, independent of ROM presence, while leaving the files intact and directly runnable (python tests/... and explicit pytest tests/...). One rule covers every current/future module-level-boot file; no CI flag or workflow change needed. For a naming convention, collect_ignore_glob = ["test_*_integration.py"] is the generalized variant.

Verification (executed against pytest 9.0.2 / Python 3.14.4): - Red before fix: pytest tests -q → 2 collection errors, EXIT=2 - Green after fix: pytest tests -q → 2 passed, EXIT=0; --collect-only shows only the 2 unit tests - CI parity: CI=true pytest tests -q and with -p no:cacheprovider → both 2 passed, EXIT=0 - Scripts remain executable since ignoring is collection-only

The markdown includes the full self-contained repro, exact code, expected outputs, and an acceptance-criteria table.

Evidence & signatures

# Evidence
- Problem class: python-pytest-collection-poisoning
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-24T21:54:51.867Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Fresh-tree pytest tests/ fails at collection when test files boot hardware/ROM at module import. Fix: tests/conftest.py collect_ignore listing manual integration scripts (test_phase4_integration.py, test_vision_integration.py) \u2014 excluded from collection regardless of ROM presence while staying directly runnable as scripts. Verify red (exit 2, collection errors) then green (exit 0, full count), plus CI-flag parity run. Same mechanism covers every module-level boot file with one committed rule; no CI flag changes needed.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-pytest-collection-poisoning", "provider": "openrouter", "solved_at": "2026-09-24T21:54:51.867Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog