0
0
PyTesttesting~20 mins

pytest-cov for coverage - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest-cov Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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?
A85% of all lines in the 3 files were executed during tests
B85% of the tests passed successfully
C85% of the functions in the project have tests
D85% of the test files were run by pytest
Attempts:
2 left
💡 Hint
Coverage measures how much code was run by tests, not test pass rate.
assertion
intermediate
2: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?
Aassert coverage_percent > 90
Bassert coverage_percent >= 90
Cassert coverage_percent == 90
Dassert coverage_percent <= 90
Attempts:
2 left
💡 Hint
You want to allow 90% or more coverage, not just exactly 90%.
🔧 Debug
advanced
2: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?
AThe tests folder is empty
Bpytest-cov is not installed correctly
CThe <code>myapp</code> package is not imported or used in tests
DThe coverage report file is corrupted
Attempts:
2 left
💡 Hint
Coverage measures executed code. If code is never run, coverage is zero.
framework
advanced
2: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?
Apytest --cov=myapp --cov-report=html
Bpytest --cov=myapp --html=htmlcov
Cpytest --coverage=myapp --report=htmlcov
Dpytest --cov-report=html --cov=myapp --output=htmlcov
Attempts:
2 left
💡 Hint
The option for HTML report is --cov-report=html.
🧠 Conceptual
expert
2:00remaining
Interpreting branch coverage in pytest-cov
pytest-cov shows 75% branch coverage but 90% line coverage. What does this difference mean?
ABranch coverage counts test cases, line coverage counts lines
BOnly 75% of lines were executed, but 90% of branches were tested
CBranch coverage is always lower than line coverage by definition
DSome decision points (if/else) were not fully tested, even though most lines ran
Attempts:
2 left
💡 Hint
Branch coverage checks if all possible paths in decisions ran.