Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to exclude a function from coverage using a comment.
PyTest
def helper_function(): # [1] pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect comment phrases like '# no coverage' or '# skip coverage'.
Forgetting the colon ':' after 'pragma'.
✗ Incorrect
The comment '# pragma: no cover' tells coverage tools to ignore this function.
2fill in blank
mediumComplete the pytest command to run tests with coverage but exclude files matching a pattern.
PyTest
pytest --cov=my_package --cov-config=setup.cfg --cov-fail-under=80 --cov-branch --cov-report=term-missing --cov-omit=[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding '*.pyc' files which are compiled files, not source files.
Excluding 'docs/*' which is unrelated to code coverage.
✗ Incorrect
The option '--cov-omit=tests/*' excludes all files in the tests folder from coverage.
3fill in blank
hardFix the error in the coverage configuration to exclude a function from coverage.
PyTest
[report]
exclude_lines =
[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using other dunder methods like __repr__ or __str__ which are not commonly excluded.
Including parentheses after the method name.
✗ Incorrect
The line 'def __init__' in exclude_lines tells coverage to ignore __init__ methods.
4fill in blank
hardFill both blanks to exclude lines with print statements and pass statements from coverage.
PyTest
[report]
exclude_lines =
[1]
[2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pragma: no cover' here which is a comment, not a line pattern.
Mixing method names with keywords.
✗ Incorrect
Lines containing 'print' and 'pass' can be excluded from coverage by listing them under exclude_lines.
5fill in blank
hardFill all three blanks to exclude a function, a class, and a line pattern from coverage.
PyTest
[report]
exclude_lines =
[1]
[2]
[3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'def main' instead of the debug function name.
Not including the main guard line pattern correctly.
✗ Incorrect
You can exclude functions, classes, and specific lines like the main guard from coverage by listing them.