0
0
PyTesttesting~20 mins

Coverage in CI pipelines in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coverage Master in CI
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Understanding coverage report output in pytest
What is the output of the following pytest coverage command snippet when run on a module with 3 functions, where 2 functions are tested and 1 is not?
PyTest
pytest --cov=my_module --cov-report=term

# Assume my_module has 3 functions: func_a, func_b, func_c
# Tests cover func_a and func_b only
ACoverage: 0% of statements executed
BCoverage: 66% of statements executed
CCoverage: 100% of statements executed
DCoverage: 33% of statements executed
Attempts:
2 left
💡 Hint
Think about how coverage percentage is calculated based on tested functions.
assertion
intermediate
2:00remaining
Correct assertion for coverage threshold in pytest
Which assertion correctly fails the test if coverage is below 80% in a pytest coverage report?
PyTest
coverage_percent = 75  # example value from coverage report

# Choose the correct assertion
Aassert coverage_percent >= 80, f"Coverage too low: {coverage_percent}%"
Bassert coverage_percent <= 80, f"Coverage too low: {coverage_percent}%"
Cassert coverage_percent > 80, f"Coverage too low: {coverage_percent}%"
Dassert coverage_percent < 80, f"Coverage too low: {coverage_percent}%"
Attempts:
2 left
💡 Hint
Coverage should be at least 80%.
locator
advanced
2:00remaining
Best practice for locating coverage report file in CI
In a CI pipeline, where should the coverage report file be stored for best accessibility and integration?
AInside the source code directory alongside the code files
BIn a temporary system directory outside the project
CIn a dedicated reports directory at the root of the project
DIn the user's home directory on the CI server
Attempts:
2 left
💡 Hint
Think about organization and ease of access for CI tools.
framework
advanced
2:00remaining
Integrating coverage checks in pytest CI pipeline
Which pytest command line option combination ensures tests fail if coverage is below 90% during CI runs?
Apytest --cov=my_module --coverage-fail=90
Bpytest --cov=my_module --fail-under=90
Cpytest --coverage=my_module --fail-under=90
Dpytest --cov=my_module --cov-fail-under=90
Attempts:
2 left
💡 Hint
Look for the correct pytest coverage fail threshold option.
🔧 Debug
expert
3:00remaining
Debugging missing coverage data in CI pipeline
In a CI pipeline, coverage reports show 0% coverage despite tests running successfully. What is the most likely cause?
ACoverage data file is overwritten before report generation
BTests are not importing the module under test
CCoverage tool is not installed in the CI environment
DCoverage measurement started after tests finished running
Attempts:
2 left
💡 Hint
Think about how coverage data files are handled in CI.