python config_error ai_generated true

CoverageWarning: Module myapp was never imported. (module-not-imported)

ID: python/pytest-cov-source-not-found

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.x active
5.x active
6.x active

Root Cause

pytest-cov was invoked with --cov=myapp but the package was never imported during the test session, often because tests import a differently named package or the source path is wrong.

generic

中文

pytest-cov 使用 --cov=myapp 调用,但测试会话期间从未导入该包,通常是因为测试导入的包名不同或源码路径错误。

Workarounds

  1. 90% success
    pytest --cov=myapp --cov-report=term-missing tests/
  2. 88% success
    # .coveragerc
    [run]
    source = src/myapp

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Changes the report format only; the module is still never imported so coverage stays at 0%.

  2. 70% fail

    Marks the module as imported but bypasses the real code paths, producing misleading 100% coverage on empty lines.