python config_error ai_generated true

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

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

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

  2. 80% fail

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