Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run pytest with coverage and fail if coverage is below 80%.
PyTest
pytest --cov=my_package --cov-fail-under=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value lower than 80 which allows lower coverage.
Using 100 which is too strict for many projects.
✗ Incorrect
The option '--cov-fail-under=80' makes pytest fail if coverage is below 80%.
2fill in blank
mediumComplete the pytest command to measure coverage for the 'utils' module only.
PyTest
pytest --cov=[1] --cov-fail-under=75
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tests' which measures test files, not source code.
Using 'setup' which is unrelated here.
✗ Incorrect
The '--cov=utils' option measures coverage only for the 'utils' module.
3fill in blank
hardFix the error in the pytest coverage command to correctly fail if coverage is below 85%.
PyTest
pytest --cov=myapp --cov-fail-under=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fail-under=85' as a value which is invalid.
Setting the threshold too low or too high.
✗ Incorrect
The correct syntax is '--cov-fail-under=85' to fail if coverage is below 85%.
4fill in blank
hardFill both blanks to create a pytest command that measures coverage for 'app' and fails if coverage is below 90%.
PyTest
pytest --cov=[1] --cov-fail-under=[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tests' instead of 'app' for coverage.
Setting threshold to 80 instead of 90.
✗ Incorrect
Use '--cov=app' to measure 'app' module and '--cov-fail-under=90' to set 90% threshold.
5fill in blank
hardFill all three blanks to create a pytest command that measures coverage for 'service', fails if coverage is below 85%, and outputs a coverage report in XML format.
PyTest
pytest --cov=[1] --cov-fail-under=[2] --cov-report=[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'html' instead of 'xml' for report format.
Setting threshold incorrectly.
✗ Incorrect
Use '--cov=service' for the module, '--cov-fail-under=85' for threshold, and '--cov-report=xml' for XML report.