Skip to content

Commit 4d4ddd8

Browse files
committed
fix: better ellipsis exclusion regex. #831
1 parent d578c52 commit 4d4ddd8

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

coverage/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def getregexlist(self, section: str, option: str) -> list[str]:
146146
# The default line exclusion regexes.
147147
DEFAULT_EXCLUDE = [
148148
r"#\s*(pragma|PRAGMA)[:\s]?\s*(no|NO)\s*(cover|COVER)",
149-
r"^\s*\.\.\.\s*(#|$)",
149+
r"^\s*(((async )?def .*?)?\)(\s*->.*?)?:\s*)?\.\.\.\s*(#|$)",
150150
]
151151

152152
# The default partial branch regexes, to be modified by the user.

doc/excluding.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ lines are automatically excluded:
7979
- Any line with a comment like ``# pragma: no cover``. Other slight
8080
differences in spacing and letter case are also recognized.
8181

82-
- Any line with only ``...`` in the code.
82+
- Any line with only ``...`` in the code, for excluding placeholder function
83+
bodies.
8384

8485
For branch coverage, these kinds of branches are automatically excluded:
8586

tests/test_coverage.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,8 +1428,25 @@ def test_default(self) -> None:
14281428
i = 9
14291429
... # we don't care about this line
14301430
k = 11
1431-
""",
1432-
lines=[1,3,5,7,9,11],
1431+
def foo12(): ... # do nothing
1432+
async def bar13(): ...
1433+
def method14(self) ->None: ...
1434+
def method15( # 15
1435+
self,
1436+
some_arg: str = "Hello",
1437+
): ...
1438+
def method19(self): return a[1,...]
1439+
def method20(
1440+
self,
1441+
some_args,
1442+
) -> int: ...
1443+
x = 24
1444+
def method25(
1445+
self,
1446+
): return a[1,...]
1447+
def f28(): print("(well): ... #2 false positive!")
1448+
""",
1449+
lines=[1,3,5,7,9,11,19,24,25]
14331450
)
14341451

14351452
def test_two_excludes(self) -> None:

tests/test_parser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,14 @@ def test_multiline_exclusion_block(self) -> None:
922922
log_message(msg, a)
923923
b = my_function2()
924924
# no cover: stop
925+
count_this()
926+
# no cover: start
927+
but_not_this()
928+
# no cover: stop
925929
""", regex)
926-
assert parser.lines_matching(regex) == {4, 5, 6, 7}
927-
assert parser.raw_statements == {1, 2, 3, 5, 6}
928-
assert parser.statements == {1, 2, 3}
930+
assert parser.lines_matching(regex) == {4, 5, 6, 7, 9, 10, 11}
931+
assert parser.raw_statements == {1, 2, 3, 5, 6, 8, 10}
932+
assert parser.statements == {1, 2, 3, 8}
929933

930934
@pytest.mark.skipif(not env.PYBEHAVIOR.match_case, reason="Match-case is new in 3.10")
931935
def test_multiline_exclusion_block2(self) -> None:

0 commit comments

Comments
 (0)