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

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-09-19First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    pytest --cov=myapp --cov-report=term-missing tests/
  2. 92% success
    # pyproject.toml
    [tool.coverage.run]
    source = ["myapp"]
    branch = true
  3. 85% success
    # tests/conftest.py
    import myapp  # noqa: F401 ensures coverage sees the package

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Branch coverage doesn't fix missing source mapping.

  2. 90% fail

    Threshold doesn't affect data collection.

  3. 85% fail

    Extra deps don't fix path/name mismatch.