python
config_error
ai_generated
true
CoverageWarning: Module myapp was never imported. (module-not-imported) CoverageWarning: No data was collected. (no-data-collected)
ID: python/pytest-coverage-source-missing
80%Fix Rate
87%Confidence
0Evidence
2024-09-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5.x | active | — | — | — |
| 6.x | active | — | — | — |
| 7.x | active | — | — | — |
Root Cause
pytest-cov was pointed at a source path that doesn't match the importable package name, or tests never import the package (e.g., only test submodules that import a different top-level name).
generic中文
pytest-cov 指向的源路径与可导入的包名不匹配,或者测试从未导入该包(例如仅测试导入了不同顶层名称的子模块)。
Workarounds
-
95% success
pytest --cov=myapp --cov-report=term-missing tests/
-
92% success
# pyproject.toml [tool.coverage.run] source = ["myapp"] branch = true
-
85% success
# tests/conftest.py import myapp # noqa: F401 ensures coverage sees the package
Dead Ends
Common approaches that don't work:
-
90% fail
Branch coverage doesn't fix missing source mapping.
-
90% fail
Threshold doesn't affect data collection.
-
85% fail
Extra deps don't fix path/name mismatch.