python config_error ai_generated true

FAIL Required test coverage of 90% not reached. Total coverage: 84.32% ERROR: Coverage failure: total of 84.32 is less than fail-under=90.00

ID: python/pytest-cov-fail-under-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-12-04First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
5.0 active

Root Cause

pytest-cov's --cov-fail-under threshold is higher than the actual measured coverage. Common when new code was added without tests, or when source paths in --cov are misconfigured so some modules show as 0%.

generic

中文

pytest-cov 的 --cov-fail-under 阈值高于实际测量的覆盖率。通常发生在添加了没有测试的新代码时,或者 --cov 中的源路径配置错误导致某些模块显示为 0%。

Workarounds

  1. 95% success
    pytest --cov=src --cov-report=term-missing --cov-fail-under=0
    # then write tests for the missing lines, or:
    pytest --cov=src --cov-report=html
    open htmlcov/index.html
  2. 90% success
    pytest --cov=src --cov-fail-under=90 \
      --cov-config=.coveragerc
    
    # .coveragerc
    [run]
    omit =
        */migrations/*
        */tests/*
        */conftest.py

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Treats the symptom; coverage continues to drift downward and the team loses the safety net.

  2. 80% fail

    Excludes code from measurement instead of testing it; reviewers reject the PR and real bugs ship untested.