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?
✗ Incorrect
The standard comment to exclude code from coverage is '# pragma: no cover'.
Which pytest plugin is used to measure code coverage?
✗ Incorrect
The 'pytest-cov' plugin integrates coverage measurement with pytest.
Where do you configure files to exclude from coverage?
✗ Incorrect
The '.coveragerc' file is used to configure coverage options including files to omit.
Why exclude code from coverage reports?
✗ Incorrect
Excluding untestable or irrelevant code keeps coverage reports accurate and meaningful.
Which of these is a valid way to exclude a file from coverage?
✗ Incorrect
Files or directories can be excluded by listing them in the 'omit' section of the .coveragerc 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.