0
0
PyTesttesting~5 mins

Excluding code from coverage in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'excluding code from coverage' mean in testing?
It means telling the coverage tool to ignore certain parts of the code when measuring how much code is tested. This helps focus on important code and avoid noise from untestable or irrelevant parts.
Click to reveal answer
beginner
How can you exclude a specific function from coverage in pytest?
You can add a comment like # pragma: no cover at the end of the function or line you want to exclude. Coverage tools will skip that code when reporting coverage.
Click to reveal answer
beginner
Which pytest plugin helps measure code coverage?
The pytest-cov plugin integrates coverage measurement with pytest, making it easy to run tests and see coverage reports.
Click to reveal answer
intermediate
Why might you want to exclude code from coverage reports?
You might exclude code that is hard to test, like debug code, platform-specific code, or code that runs only in rare cases. This keeps coverage numbers meaningful and avoids false negatives.
Click to reveal answer
intermediate
How do you exclude entire files or directories from coverage in pytest?
You can configure the .coveragerc file with an omit section listing files or folders to skip. For example, omit = tests/* excludes all test files.
Click to reveal answer
What comment tells coverage tools to ignore a line or function?
A# no test
B# pragma: no cover
C# skip test
D# ignore coverage
Which pytest plugin is used to measure code coverage?
Apytest-coverage
Bpytest-report
Cpytest-cov
Dpytest-check
Where do you configure files to exclude from coverage?
A.coveragerc
Bsetup.cfg
Cpytest.ini
Dtox.ini
Why exclude code from coverage reports?
ATo increase coverage percentage artificially
BTo reduce test time
CTo hide bugs
DTo keep coverage meaningful by ignoring untestable code
Which of these is a valid way to exclude a file from coverage?
AList the file in the 'omit' section of .coveragerc
BAdd '# no cover' comment at the top
CRename the file with .nocov extension
DUse pytest command line option '--exclude-file'
Explain how to exclude a specific function from coverage in pytest and why you might do it.
Think about marking code lines and reasons for ignoring coverage.
You got /3 concepts.
    Describe how to exclude entire files or folders from coverage reports using configuration.
    Focus on configuration file and syntax.
    You got /3 concepts.