Given the following Python code with coverage exclusion comments, what will be the total coverage percentage reported by pytest-cov?
def add(a, b): return a + b # pragma: no cover def unused_function(): print("This function is not covered") result = add(2, 3) print(result)
Code marked with # pragma: no cover is excluded from coverage.
The function unused_function is excluded from coverage by the # pragma: no cover comment. Only add is counted and fully covered, so coverage is 100%.
Which assertion correctly verifies that a function marked with # pragma: no cover is excluded from coverage reports?
Functions excluded from coverage should not appear in executed functions list.
The function marked with # pragma: no cover is not executed or counted in coverage, so it should not appear in the list of executed functions.
Given this code snippet, coverage reports include helper_function even though it has # pragma: no cover. What is the most likely reason?
def main():
helper_function()
# pragma: no cover
def helper_function():
print("Helper")
main()Placement of exclusion comments matters for coverage tools.
The # pragma: no cover comment must be placed on the function definition line or immediately after it. Placing it below or separated causes coverage tools to ignore it.
Which pytest-cov configuration snippet correctly excludes all files in the tests/helpers/ directory from coverage reports?
Check pytest-cov documentation for the correct section and key to omit files.
The omit option under the [run] section tells coverage.py which files to exclude from coverage measurement.
Which statement best describes the impact of excluding code with # pragma: no cover on overall test coverage metrics?
Think about how coverage percentage is calculated.
Excluding code removes it from the total lines counted, so coverage percentage is calculated over fewer lines, often increasing the percentage.