python
module_error
ai_generated
true
Failed: [doctest] mymodule.func UNEXPECTED EXCEPTION: ModuleNotFoundError: No module named 'mymodule'
ID: python/pytest-doctest-import-error
80%Fix Rate
85%Confidence
0Evidence
2024-10-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest-doctest tries to import the module from the doctest file, but the module is not on sys.path because tests run from a different directory.
generic中文
pytest-doctest 尝试从 doctest 文件导入模块,但模块不在 sys.path 上,因为测试从不同目录运行。
Workarounds
-
95% success
pip install -e . pytest --doctest-modules
-
90% success
In pytest.ini: `[pytest] pythonpath = .`
Dead Ends
Common approaches that don't work:
-
60% fail
May work locally but fails in CI where the working directory differs.
-
80% fail
Loses doctest coverage; not a fix.