python config_error ai_generated true

CoverageWarning: No data was collected. (no-data-collected) WARNING: Failed to find data for module 'myapp'

ID: python/pytest-coverage-no-data-collected

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
5.x active — — —
7.x active — — —

Root Cause

coverage run was pointed at the wrong source, or pytest is executed under a different interpreter/subprocess than the one coverage instruments. Common when using pytest-xdist without --cov or when tests spawn subprocesses that coverage does not trace.

generic

中文

coverage run 指向了错误的源码,或者 pytest 在与 coverage 插桩不同的解释器/子进程中执行。常见于使用 pytest-xdist 但未加 --cov,或测试启动的子进程未被 coverage 追踪。

Workarounds

  1. 94% success
    pip install pytest-cov
    pytest --cov=myapp --cov-report=term-missing -n auto
  2. 85% success
    # .coveragerc
    [run]
    concurrency = multiprocessing
    parallel = True
    source = myapp

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Broadens the source but if coverage is not started under the same process, still collects nothing.

  2. 65% fail

    Correct in principle, but if pytest-xdist is active the workers are separate processes and the main process records no data.