Skip to content

Commit 9209c55

Browse files
committed
fix: don't report branches to exclusions as missing. #1271
1 parent 05562e4 commit 9209c55

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ This list is detailed and covers changes in each pre-release version.
2222
Unreleased
2323
----------
2424

25+
- Fix: Complex conditionals over excluded lines could have incorrectly reported
26+
a missing branch (`issue 1271`_). This is now fixed.
27+
2528
- Fix: Removed another vestige of jQuery from the source tarball
2629
(`issue 840`_).
2730

31+
.. _issue 1271: https://github.com/nedbat/coveragepy/issues/1271
32+
2833

2934
.. _changes_611:
3035

coverage/results.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ def arcs_executed(self):
8484

8585
@contract(returns='list(tuple(int, int))')
8686
def arcs_missing(self):
87-
"""Returns a sorted list of the arcs in the code not executed."""
87+
"""Returns a sorted list of the unexecuted arcs in the code."""
8888
possible = self.arc_possibilities()
8989
executed = self.arcs_executed()
9090
missing = (
9191
p for p in possible
9292
if p not in executed
9393
and p[0] not in self.no_branch
94+
and p[1] not in self.excluded
9495
)
9596
return sorted(missing)
9697

tests/test_coverage.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ def test_excluding_try_except(self):
14921492
""",
14931493
[1,2,3,7,8], "", excludes=['#pragma: NO COVER'],
14941494
arcz=".1 12 23 37 45 58 78 8.",
1495-
arcz_missing="45 58",
1495+
arcz_missing="58",
14961496
)
14971497

14981498
def test_excluding_try_except_stranded_else(self):
@@ -1599,6 +1599,20 @@ def test_formfeed(self):
15991599
[1, 6], "", excludes=['assert'],
16001600
)
16011601

1602+
def test_excluded_comprehension_branches(self):
1603+
# https://github.com/nedbat/coveragepy/issues/1271
1604+
self.check_coverage("""\
1605+
x, y = [0], [1]
1606+
if x == [2]:
1607+
raise NotImplementedError # pragma: NO COVER
1608+
if all(_ == __ for _, __ in zip(x, y)):
1609+
raise NotImplementedError # pragma: NO COVER
1610+
""",
1611+
[1,2,4], "", excludes=['#pragma: NO COVER'],
1612+
arcz=".1 12 23 24 45 4. -44 4-4",
1613+
arcz_missing="4-4",
1614+
)
1615+
16021616

16031617
class Py24Test(CoverageTest):
16041618
"""Tests of new syntax in Python 2.4."""

0 commit comments

Comments
 (0)