Challenge - 5 Problems
pytest-cov Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Understanding pytest-cov output summary
You run pytest with pytest-cov on a project with 3 Python files. The coverage report shows 85% coverage overall. What does this mean?
Attempts:
2 left
💡 Hint
Coverage measures how much code was run by tests, not test pass rate.
✗ Incorrect
pytest-cov measures how many lines of code were executed during tests. 85% coverage means 85% of all lines in the files ran at least once.
❓ assertion
intermediate2:00remaining
Correct assertion to check coverage threshold
You want your pytest-cov to fail tests if coverage is below 90%. Which assertion in your pytest test is correct?
Attempts:
2 left
💡 Hint
You want to allow 90% or more coverage, not just exactly 90%.
✗ Incorrect
The assertion should check coverage is at least 90%, so using >= 90 is correct.
🔧 Debug
advanced2:00remaining
Why does pytest-cov report 0% coverage?
You run
pytest --cov=myapp tests/ but the coverage report shows 0% coverage. What is the most likely cause?Attempts:
2 left
💡 Hint
Coverage measures executed code. If code is never run, coverage is zero.
✗ Incorrect
If the tested package is not imported or run during tests, coverage will be zero because no code was executed.
❓ framework
advanced2:00remaining
Configuring pytest-cov to generate HTML report
Which pytest command correctly runs tests with coverage and generates an HTML coverage report in the
htmlcov folder?Attempts:
2 left
💡 Hint
The option for HTML report is --cov-report=html.
✗ Incorrect
The correct syntax is --cov-report=html to generate an HTML report in the default htmlcov folder.
🧠 Conceptual
expert2:00remaining
Interpreting branch coverage in pytest-cov
pytest-cov shows 75% branch coverage but 90% line coverage. What does this difference mean?
Attempts:
2 left
💡 Hint
Branch coverage checks if all possible paths in decisions ran.
✗ Incorrect
Branch coverage measures if all possible paths in code decisions were tested. 75% means some if/else paths were missed, even if 90% of lines ran.