python
module_error
ai_generated
true
import file mismatch: tests/test_a.py has __pycache__ but tests/test_a.py has different __pycache__ HINT: remove __pycache__ files or use --import-mode=importlib
ID: python/pytest-import-mode-conflict
80%Fix Rate
90%Confidence
0Evidence
2024-06-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Two test files share the same module basename (e.g. tests/api/test_a.py and tests/db/test_a.py) and neither directory has an __init__.py, so pytest's prepend import mode collides on the module name.
generic中文
两个测试文件共享相同的模块基名(例如 tests/api/test_a.py 和 tests/db/test_a.py),且两个目录都没有 __init__.py,因此 pytest 的 prepend 导入模式在模块名上冲突。
Workarounds
-
95% success
# pytest.ini [pytest] importmode = importlib
-
90% success
touch tests/__init__.py tests/api/__init__.py tests/db/__init__.py
Dead Ends
Common approaches that don't work:
-
65% fail
Clears the symptom for one run; the next run recreates the collision.
-
50% fail
Works but does not scale; the next same-named file reintroduces the problem.