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
Two pytest infrastructure traps that hit every multi-module project:
tests/__init__.py files cause pytest plugin-name collisions under --import-mode=importlib. When the workspace root pyproject sets addopts = "--import-mode=importlib", having modules/<m>/tests/__init__.py files in two modules makes pytest try to register tests.conftest as a plugin twice — collision error. The fix is to not create tests/__init__.py; pytest discovers test files via path walk under importlib mode.
pytest_plugins = [...] in non-top-level conftest is forbidden by pytest 7.x. The framework's bundled host_conftest.py is meant to be loaded as a plugin, but if a module's conftest tries to register it via pytest_plugins, pytest raises:
pytest_plugins variable is not allowed in non-rootdir conftest.py files
Fix: register at the workspace-root conftest.py (one level above all modules) with pytest_plugins = ["host_conftest"]. Module conftests then inherit the plugin.
Reproduction
# Trap 1echo> modules/lacowiki_legends/tests/__init__.py
echo> modules/lacowiki_datasets/tests/__init__.py
uv run pytest modules
# → "tests.conftest" plugin registered twice / import collision# Trap 2# In modules/lacowiki_legends/tests/conftest.py:
pytest_plugins = ["host_conftest"]
uv run pytest
# → ERROR: pytest_plugins variable is not allowed in non-rootdir conftest.py files
Workarounds
Don't create tests/__init__.py. Test files import via path discovery.
Workspace root has a single conftest.py with pytest_plugins = ["host_conftest"]. Module conftests are named conftest.py (no __init__.py parent) and just declare local fixtures.
Suggested fix
Update the framework docs / sm new scaffold to:
Not create tests/__init__.py in any module template.
Generate a workspace-root conftest.py with pytest_plugins = ["host_conftest"] when scaffolding a uv-workspace project.
Document the importlib-mode + plugin-registration pattern prominently.
Closing — addressed by commit ade3e24 (PR #98). The module scaffold no longer creates tests/__init__.py, eliminating the tests.conftest plugin-name collision under --import-mode=importlib. The workspace-root conftest.py already registers shared fixtures, so module conftests just declare local fixtures.
Activity
fix: address framework papercuts (#66, #68, #71, #73, #75, #76, #81, #90
antosubash commentedon May 1, 2026
Closing — addressed by commit ade3e24 (PR #98). The module scaffold no longer creates
tests/__init__.py, eliminating thetests.conftestplugin-name collision under--import-mode=importlib. The workspace-rootconftest.pyalready registers shared fixtures, so module conftests just declare local fixtures.Generated by Claude Code