python config_error ai_generated true

覆盖率错误:未收集到模块 'my_module' 的数据

CoverageError: No data collected for module 'my_module'

ID: python/pytest-cov-coverage-error

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-08-20首次发现

版本兼容性

版本状态引入弃用备注
3.9 active
3.10 active

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

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

    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% 失败

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