python config_error ai_generated true

CoverageWarning: 未收集到任何数据。(no-data-collected) warnings.warn("未收集到任何数据。", CoverageWarning)

CoverageWarning: No data was collected. (no-data-collected) warnings.warn("No data was collected.", CoverageWarning)

ID: python/pytest-cov-no-data-collected-warning

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

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

coverage 已启动但从未停止,或传给 `--cov` 的源路径不匹配任何已导入模块。常见于测试导入的是已安装副本而非 CWD 中的包,或 `--cov=src` 不存在。

English

coverage was started but never stopped, or the source path passed to `--cov` does not match any imported module. Common when tests import a different installed copy of the package than the one in CWD, or when `--cov=src` doesn't exist.

generic

解决方案

  1. 93% 成功率
    pip install -e .
    pytest --cov=myapp --cov-report=term-missing
    # or
    pytest --cov=src/myapp
  2. 90% 成功率
    # pyproject.toml
    [tool.coverage.run]
    source = ["myapp"]
    
    [tool.pytest.ini_options]
    addopts = "--cov --cov-report=term-missing"

无效尝试

常见但无效的做法:

  1. 70% 失败

    The report has no data to display; it just prints an empty table.

  2. 80% 失败

    Two coverage processes conflict; the .coverage file is corrupted or overwritten.