python config_error ai_generated true

Coverage.py warning: No data was collected. (no-data-collected) WARNING: Failed to generate report: No data to report.

ID: python/pytest-coverage-subprocess-not-measured

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-01-27First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.4.x active — — —
7.5.x active — — —

Root Cause

Tests spawn subprocesses (e.g., via subprocess.run or multiprocessing) and coverage is not propagated to them, so only the parent process is measured and often has no executed lines.

generic

中文

测试生成子进程(例如通过 subprocess.run 或 multiprocessing),覆盖率未传播到子进程,因此仅测量父进程,而父进程通常没有执行任何行。

Workarounds

  1. 90% success
    # .coveragerc
    [run]
    concurrency = multiprocessing
    parallel = true
    
    # conftest.py
    import coverage
    coverage.process_startup()
    
    # env
    COVERAGE_PROCESS_START=.coveragerc
  2. 88% success
    coverage run --concurrency=multiprocessing -m pytest tests/
    coverage combine
    coverage report --fail-under=85

Dead Ends

Common approaches that don't work:

  1. 85% fail

    If the tests themselves only spawn subprocesses, the parent process executes no application code and coverage stays empty.

  2. 80% fail

    Only affects where data is written, not whether subprocesses are instrumented; the child still does not start coverage.