python config_error ai_generated true

Coverage.py 警告: 未收集到数据。(no-data-collected) 警告: 生成报告失败: 无数据可报告。

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

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

版本兼容性

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

根因分析

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

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 85% 失败

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

  2. 80% 失败

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