Open cjw296 opened 4 years ago
https://coverage.readthedocs.io/en/coverage-5.3/excluding.html#advanced-exclusion
Coverage.py identifies exclusions by matching lines against a list of regular expressions.
...
is recognized as a regular expression. You need to escape it :)
Sure, I wonder if there should be a blacklist of regexes?
I could make a deny list that included "...", but:
I guess this could grow as people report things? ... is problematic for me because it's a python literal that I use commonly in tests to indicate "this isn't import to the test" more explicitly than a pass statement.
Another good safety net might be that all code in a file is excluded even though the file itself hasn't been excluded?
Yes, that, but maybe for multiple exclude patterns? I can't think of a legit use case where a whole file would end up being excluded by ever line in it matching one or more exclude regexes.
Since a corrected regular expression hasn't been mentioned yet I'd suggest the following: ellipsis with leading whitespace: ^\s*\.\.\.
Can be added to pyproject.toml
like this:
[tool.coverage.report]
exclude_lines = ['^\s*\.\.\.']
Or .coveragerc
like this:
[report]
exclude_lines =
^\s*\.\.\.
Excludes the ...
commonly used in never-called function stubs, including ones with inline comments:
def foo():
... # comment
But doesn't exclude general uses of ...
in code:
foo = ...
def baz(
x = ...,
):
"""..."""
pass # ...
baz(...)
The only problematic code I can think of is an ellipsis within a multi-line statement:
foo = (
...,
)
bar = (
...
)
"""
...
"""
Perhaps the docs could mention this regular expression as the correct way of excluding ...
.
Describe the bug
Adding this to
.coveragerc
results in all source being ignored:To Reproduce How can we reproduce the problem? Please be specific. Don't just link to a failing CI job. Answer the questions below:
rm -f .coverage && coverage run -m pytest && coverage report
Expected behavior
Only lines of the following form to be excluded from coverage checking:
Additional context
The results of the output from this bug are super confusing:
...but I guess that makes sense in the context of the ellipsis causing all lines to be excluded.