Challenge - 5 Problems
Coverage Threshold Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test result with coverage threshold set to 80%?
Given the following pytest coverage configuration, what will be the test execution result if the actual coverage is 75%?
PyTest
[run] branch = True [report] fail_under = 80 [paths] source = src # Assume tests run and coverage measured at 75%
Attempts:
2 left
💡 Hint
Coverage fail_under sets minimum coverage percentage to pass tests.
✗ Incorrect
The fail_under setting enforces a minimum coverage percentage. If actual coverage is below 80%, tests fail.
❓ assertion
intermediate1:30remaining
Which assertion correctly checks coverage threshold in pytest?
You want to assert that coverage is at least 90% in a pytest test. Which assertion is correct?
PyTest
def test_coverage(coverage_percent): # coverage_percent is a float representing coverage %
Attempts:
2 left
💡 Hint
Threshold means coverage must be equal or greater than the set value.
✗ Incorrect
Using >= 90 ensures coverage is at least 90%, matching threshold requirements.
🔧 Debug
advanced2:00remaining
Why does coverage threshold fail even though coverage is 85%?
You set fail_under=85 in your coverage config but tests fail with coverage 85%. What is the likely cause?
PyTest
[report] fail_under = 85 # Actual coverage measured: 85.0%
Attempts:
2 left
💡 Hint
Check if fail_under is inclusive or exclusive of the threshold value.
✗ Incorrect
fail_under fails the build only if coverage < 85%. Coverage of 85% (>=85%) should pass, so failure is unexpected (e.g., due to floating-point precision, branch coverage, or per-file thresholds).
🧠 Conceptual
advanced1:30remaining
What is the purpose of coverage thresholds in testing?
Why do teams use coverage thresholds in their test suites?
Attempts:
2 left
💡 Hint
Think about quality control in testing.
✗ Incorrect
Coverage thresholds enforce a minimum tested code percentage, helping maintain code quality.
❓ framework
expert2:00remaining
How to configure pytest-cov to fail tests if coverage is below 75%?
Which pytest command line option correctly enforces a 75% coverage threshold that fails tests if not met?
Attempts:
2 left
💡 Hint
Check pytest-cov documentation for correct flag names.
✗ Incorrect
The correct flag is --cov-fail-under to set minimum coverage threshold.