0
0
PyTesttesting~20 mins

pytest-cov setup - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest-cov Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of pytest-cov in testing

What is the main purpose of using pytest-cov in a Python testing environment?

ATo measure how much of the code is executed during tests
BTo automatically fix bugs found during tests
CTo speed up test execution by parallelizing tests
DTo generate test data for parameterized tests
Attempts:
2 left
💡 Hint

Think about what 'cov' in pytest-cov might stand for.

Predict Output
intermediate
1:30remaining
Output of pytest-cov command

What output will you see after running this command?

pytest --cov=my_module tests/

Assume my_module has 100 lines, and tests cover 80 lines.

AA list of all tests run without coverage information
BAn error saying <code>--cov</code> is an unknown option
CA coverage report showing 80% coverage of <code>my_module</code>
DA coverage report showing 100% coverage of <code>my_module</code>
Attempts:
2 left
💡 Hint

Think about what coverage means and what the command requests.

locator
advanced
2:00remaining
Correct pytest-cov configuration in pytest.ini

Which pytest.ini configuration correctly enables coverage reporting for the app package and generates an XML report?

A
[pytest]
addopts = --cov app --cov-report xml
B
[pytest]
addopts = --cov=app --cov-report=xml
C
[pytest]
addopts = --coverage=app --coverage-report=xml
D
[pytest]
coverage = app
coverage_report = xml
Attempts:
2 left
💡 Hint

Check the exact option names for pytest-cov.

assertion
advanced
1:30remaining
Valid assertion for coverage percentage in pytest-cov report

Which assertion correctly checks that the coverage percentage is at least 90% in a pytest-cov generated report stored as a variable coverage_percent?

Aassert coverage_percent < 90
Bassert coverage_percent > 90
Cassert coverage_percent == 90
Dassert coverage_percent >= 90
Attempts:
2 left
💡 Hint

Think about including 90% as acceptable coverage.

🔧 Debug
expert
2:00remaining
Identify the cause of missing coverage report

You ran pytest --cov=myapp tests/ but no coverage report is generated. Which is the most likely cause?

AThe <code>pytest-cov</code> plugin is not installed
BThe tests folder is empty
CThe <code>myapp</code> folder has no Python files
DThe <code>pytest.ini</code> file is missing
Attempts:
2 left
💡 Hint

Think about what enables coverage reporting in pytest.