0
0
PyTesttesting~20 mins

Coverage thresholds in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coverage Threshold Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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%
ATests pass, coverage report shows 75%
BTests pass but warning about coverage below threshold
CTests fail due to syntax error in config
DTests fail due to coverage below 80%
Attempts:
2 left
💡 Hint
Coverage fail_under sets minimum coverage percentage to pass tests.
assertion
intermediate
1: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 %
Aassert coverage_percent > 90
Bassert coverage_percent >= 90
Cassert coverage_percent == 90
Dassert coverage_percent <= 90
Attempts:
2 left
💡 Hint
Threshold means coverage must be equal or greater than the set value.
🔧 Debug
advanced
2: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%
Afail_under requires coverage greater or equal to 85%, so failure is unexpected
Bfail_under requires coverage strictly greater than 85%
Cfail_under is ignored if branch coverage is enabled
Dfail_under requires coverage less than 85%
Attempts:
2 left
💡 Hint
Check if fail_under is inclusive or exclusive of the threshold value.
🧠 Conceptual
advanced
1:30remaining
What is the purpose of coverage thresholds in testing?
Why do teams use coverage thresholds in their test suites?
ATo ensure a minimum percentage of code is tested to maintain quality
BTo guarantee tests run faster by skipping untested code
CTo automatically fix uncovered code during tests
DTo disable tests if coverage is too high
Attempts:
2 left
💡 Hint
Think about quality control in testing.
framework
expert
2: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?
Apytest --cov=src --fail-under=75
Bpytest --coverage=src --fail-under=75
Cpytest --cov=src --cov-fail-under=75
Dpytest --cov=src --cov-fail-over=75
Attempts:
2 left
💡 Hint
Check pytest-cov documentation for correct flag names.