python config_error ai_generated true

CoverageError: No data collected for module 'my_module'

ID: python/pytest-cov-coverage-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active

Root Cause

The coverage plugin (pytest-cov) is not properly configured to measure the target module, often due to missing --cov option or incorrect module path.

generic

中文

覆盖率插件 (pytest-cov) 未正确配置以测量目标模块,通常是由于缺少 --cov 选项或模块路径不正确。

Workarounds

  1. 95% success Specify the module to measure using --cov flag.
    pytest --cov=my_module
  2. 90% success Configure coverage in pyproject.toml under [tool.coverage.run] section.
    [tool.coverage.run]
    source = ['my_module']

Dead Ends

Common approaches that don't work:

  1. Adding --cov-report=html without specifying --cov 80% fail

    Coverage data collection requires --cov to specify the module; without it, no data is collected.

  2. Setting coverage in setup.cfg but not using --cov on command line 70% fail

    Command-line options override config file; if --cov is missing, coverage may not run.