Recall & Review
beginner
What is a coverage threshold in testing?
A coverage threshold is a set minimum percentage of code that must be tested. If tests cover less than this, the test run fails.
Click to reveal answer
beginner
How do you set a coverage threshold in pytest?
You set it using the
--cov-fail-under option followed by a number, like --cov-fail-under=80 to require at least 80% coverage.Click to reveal answer
beginner
Why use coverage thresholds?
Coverage thresholds help keep tests thorough. They stop code from being accepted if tests don't cover enough, improving quality.
Click to reveal answer
beginner
What happens if coverage is below the threshold in pytest?
The test run fails and pytest returns a non-zero exit code. This alerts you to add more tests.
Click to reveal answer
intermediate
Can coverage thresholds be set for specific parts of code?
Yes, you can set thresholds for the whole project or for specific files or directories using configuration files like
.coveragerc.Click to reveal answer
What does the pytest option
--cov-fail-under=90 do?✗ Incorrect
The option
--cov-fail-under=90 makes pytest fail the test run if coverage is less than 90%.Why is setting a coverage threshold useful?
✗ Incorrect
Coverage thresholds ensure tests cover enough code to catch bugs and maintain quality.
If coverage is 75% but threshold is 80%, what happens?
✗ Incorrect
If coverage is below the threshold, pytest fails the test run to signal insufficient testing.
Can coverage thresholds be set per file in pytest?
✗ Incorrect
Pytest allows setting coverage thresholds per file or directory via configuration files like
.coveragerc.What exit code does pytest return if coverage threshold is not met?
✗ Incorrect
Pytest returns a non-zero exit code to indicate failure when coverage thresholds are not met.
Explain how to enforce a minimum coverage percentage using pytest.
Think about the command line option that sets the minimum coverage.
You got /3 concepts.
Describe why coverage thresholds improve software quality.
Consider the role of tests in catching problems.
You got /3 concepts.