0
0
PyTesttesting~10 mins

Excluding code from coverage in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A# skip coverage
B# no coverage
C# pragma: no cover
D# exclude coverage
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect comment phrases like '# no coverage' or '# skip coverage'.
Forgetting the colon ':' after 'pragma'.
2fill in blank
medium

Complete 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'
A*.pyc
Bdocs/*
Csetup.py
Dtests/*
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding '*.pyc' files which are compiled files, not source files.
Excluding 'docs/*' which is unrelated to code coverage.
3fill in blank
hard

Fix 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'
Adef __init__
Bdef __str__
Cdef __repr__
Ddef __eq__
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.
4fill in blank
hard

Fill 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'
Apragma: no cover
Bdef __init__
Cprint
Dpass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pragma: no cover' here which is a comment, not a line pattern.
Mixing method names with keywords.
5fill in blank
hard

Fill 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'
Adef debug_function
Bclass DebugHelper
Cif __name__ == .__main__.:
Ddef main
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'def main' instead of the debug function name.
Not including the main guard line pattern correctly.