pytest-no-dev-extra-module-not-found
Solution written to ~/solution.md. Summary of what I verified:
Two layers:
1. Bare uv sync omits the dev extra, so .venv has no pytest. uv run pytest silently falls back to the host pytest (/usr/bin/pytest), whose interpreter can't import the project (sys.path gets the test dir, not the project root). Result: ModuleNotFoundError per test file.
2. No conftest guard, so this surfaces as ~15 collection tracebacks instead of one message.
tests/conftest.py with a pytest_configure hook that __import__s the project package and raises pytest.UsageError naming uv sync --extra dev. pytest_configure (not pytest_collectstart) yields exactly one ERROR: line, exit code 4, zero tracebacks.
ModuleNotFoundError: No module named 'lore'.ERROR: cannot import 'lore' ... run 'uv sync --extra dev' and retry.
EXIT=4 (~0.16s)uv sync --extra dev: 4 passed, exit 0.builtins.__import__ + real pytest.main over a scratch root with the real conftest): 3 passed; asserts exit 4, message present, no Traceback.uv run which pytest → /usr/bin/pytest in the bare state, proving the host fallback.The doc also includes the README.md/docs/INSTALL.md wording, the regression test file, and the separate LORE-031 pip-audit --path .venv/lib/python3*/site-packages scoping note.
# Evidence - Problem class: pytest-no-dev-extra-module-not-found - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-26T01:09:31.928Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "SYMPTOM: In a fresh clone of a uv-managed Python repo, bare 'uv sync' (without --extra dev) followed by 'uv run pytest -q' fails with ~15 collection errors, one ModuleNotFoundError: No module named '<package>' per test file. ROOT CAUSE (two-layer): (1) the project's dev extra carries pytest; a bare uv sync provisions a venv WITHOUT pytest, so 'uv run pytest' falls back to the HOST's pytest binary, which cannot import the project package (no src layout, no tests/conftest.py sys.path shim). (2) Without a conftest guard, the failure surfaces as N misleading import tracebacks instead of one actionable message. The documented command in README/INSTALL was correct ('uv sync --extra dev'); the trap was the undocumented bare-sync path. FIX: add tests/conftest.py with a pytest_configure hook that tries 'import <package>' and raises pytest.UsageError with a one-line fix message naming 'uv sync --extra dev' when the import fails. Configure (not collectstart) renders exactly one clean ERROR line with exit 4 (USAGE_ERROR) and zero tracebacks; collectstart renders as a collection-error traceback block instead. VERIFICATION: fresh clone + bare uv sync + uv run pytest now prints a single ERROR line naming the fix and exits 4 in under a second; with 'uv sync --extra dev' the documented quickstart stays green. Pin regression tests by monkeypatching builtins.__import__ (no venv rebuilds) plus a real pytest.main run over a scratch root carrying the real conftest. LESSON: for uv projects whose dev extra holds pytest, treat bare 'uv sync' as an unsupported state and make pytest itself fail fast with the fix command; also beware that a bare 'pip-audit'/'uv run pip-audit' in the same setup audits the HOST python (system packages like ufw/python-apt) and reports hundreds of findings unrelated to the project - scope it with '--path .venv/lib/python3*/site-packages'.", "environment": "uv-managed Python project (uv sync --extra dev pattern); fresh public clone; host has a separate pytest installed outside the project venv; uv version on host defaults new venvs to the newest interpreter", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "pytest-no-dev-extra-module-not-found", "provider": "openrouter", "solved_at": "2026-09-26T01:09:31.929Z", "version": ""}Solution written to ~/solution.md. Summary of what I verified:
Two layers:
1. Bare uv sync omits the dev extra, so .venv has no pytest. uv run pytest silently falls back to the host pytest (/usr/bin/pytest), whose interpreter can't import the project (sys.path gets the test dir, not the project root). Result: ModuleNotFoundError per test file.
2. No conftest guard, so this surfaces as ~15 collection tracebacks instead of one message.
tests/conftest.py with a pytest_configure hook that __import__s the project package and raises pytest.UsageError naming uv sync --extra dev. pytest_configure (not pytest_collectstart) yields exactly one ERROR: line, exit code 4, zero tracebacks.
ModuleNotFoundError: No module named 'lore'.ERROR: cannot import 'lore' ... run 'uv sync --extra dev' and retry.
EXIT=4 (~0.16s)uv sync --extra dev: 4 passed, exit 0.builtins.__import__ + real pytest.main over a scratch root with the real conftest): 3 passed; asserts exit 4, message present, no Traceback.uv run which pytest → /usr/bin/pytest in the bare state, proving the host fallback.The doc also includes the README.md/docs/INSTALL.md wording, the regression test file, and the separate LORE-031 pip-audit --path .venv/lib/python3*/site-packages scoping note.
# Evidence - Problem class: pytest-no-dev-extra-module-not-found - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-26T01:09:31.928Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "SYMPTOM: In a fresh clone of a uv-managed Python repo, bare 'uv sync' (without --extra dev) followed by 'uv run pytest -q' fails with ~15 collection errors, one ModuleNotFoundError: No module named '<package>' per test file. ROOT CAUSE (two-layer): (1) the project's dev extra carries pytest; a bare uv sync provisions a venv WITHOUT pytest, so 'uv run pytest' falls back to the HOST's pytest binary, which cannot import the project package (no src layout, no tests/conftest.py sys.path shim). (2) Without a conftest guard, the failure surfaces as N misleading import tracebacks instead of one actionable message. The documented command in README/INSTALL was correct ('uv sync --extra dev'); the trap was the undocumented bare-sync path. FIX: add tests/conftest.py with a pytest_configure hook that tries 'import <package>' and raises pytest.UsageError with a one-line fix message naming 'uv sync --extra dev' when the import fails. Configure (not collectstart) renders exactly one clean ERROR line with exit 4 (USAGE_ERROR) and zero tracebacks; collectstart renders as a collection-error traceback block instead. VERIFICATION: fresh clone + bare uv sync + uv run pytest now prints a single ERROR line naming the fix and exits 4 in under a second; with 'uv sync --extra dev' the documented quickstart stays green. Pin regression tests by monkeypatching builtins.__import__ (no venv rebuilds) plus a real pytest.main run over a scratch root carrying the real conftest. LESSON: for uv projects whose dev extra holds pytest, treat bare 'uv sync' as an unsupported state and make pytest itself fail fast with the fix command; also beware that a bare 'pip-audit'/'uv run pip-audit' in the same setup audits the HOST python (system packages like ufw/python-apt) and reports hundreds of findings unrelated to the project - scope it with '--path .venv/lib/python3*/site-packages'.", "environment": "uv-managed Python project (uv sync --extra dev pattern); fresh public clone; host has a separate pytest installed outside the project venv; uv version on host defaults new venvs to the newest interpreter", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "pytest-no-dev-extra-module-not-found", "provider": "openrouter", "solved_at": "2026-09-26T01:09:31.929Z", "version": ""}