python config_error ai_generated true

CoverageWarning: No data was collected. (no-data-collected)

ID: python/pytest-cov-missing-coverage-data

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-02-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.1.0 active
5.0.0 active

Root Cause

The pytest-cov plugin did not detect any code execution during tests, possibly because the test files are not importing the source modules, or the source code paths are misconfigured.

generic

中文

pytest-cov插件在测试期间未检测到任何代码执行,可能是因为测试文件未导入源模块,或源代码路径配置错误。

Workarounds

  1. 90% success Ensure test files import the source modules that should be covered
    In your test file, add: from myproject import mymodule
    Then run: pytest --cov=myproject tests/
  2. 85% success Specify the source directory correctly in pytest.ini or pyproject.toml
    Add to pyproject.toml:
    [tool.pytest.ini_options]
    addopts = "--cov=src"
    cov_source = ["src"]
    Then run pytest.

Dead Ends

Common approaches that don't work:

  1. Reinstalling pytest-cov via pip 80% fail

    The issue is not with the installation but with the test configuration or code structure.

  2. Adding `--cov=myproject` without ensuring the source code is actually executed 60% fail

    If the tests don't import the source modules, coverage still won't collect data.