0
0
PyTesttesting~5 mins

Coverage thresholds in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AFails tests if coverage is below 90%
BSets coverage to exactly 90%
CIgnores coverage below 90%
DRuns tests only on 90% of code
Why is setting a coverage threshold useful?
ATo skip tests
BTo speed up tests
CTo reduce code size
DTo ensure tests cover enough code
If coverage is 75% but threshold is 80%, what happens?
ATest run passes
BTest run fails
CCoverage is ignored
DTests rerun automatically
Can coverage thresholds be set per file in pytest?
AYes, using configuration files
BNo, only global thresholds
COnly for test files
DOnly for Python 2
What exit code does pytest return if coverage threshold is not met?
AZero exit code
BExit code 100
CNon-zero exit code
DNo exit code
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.