Skip to content

Commit

Permalink
fix: don't report branches to exclusions as missing. #1271
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 5, 2021
1 parent 05562e4 commit 9209c55
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -22,9 +22,14 @@ This list is detailed and covers changes in each pre-release version.
Unreleased
----------

- Fix: Complex conditionals over excluded lines could have incorrectly reported
a missing branch (`issue 1271`_). This is now fixed.

- Fix: Removed another vestige of jQuery from the source tarball
(`issue 840`_).

.. _issue 1271: https://github.com/nedbat/coveragepy/issues/1271


.. _changes_611:

Expand Down
3 changes: 2 additions & 1 deletion coverage/results.py
Expand Up @@ -84,13 +84,14 @@ def arcs_executed(self):

@contract(returns='list(tuple(int, int))')
def arcs_missing(self):
"""Returns a sorted list of the arcs in the code not executed."""
"""Returns a sorted list of the unexecuted arcs in the code."""
possible = self.arc_possibilities()
executed = self.arcs_executed()
missing = (
p for p in possible
if p not in executed
and p[0] not in self.no_branch
and p[1] not in self.excluded
)
return sorted(missing)

Expand Down
16 changes: 15 additions & 1 deletion tests/test_coverage.py
Expand Up @@ -1492,7 +1492,7 @@ def test_excluding_try_except(self):
""",
[1,2,3,7,8], "", excludes=['#pragma: NO COVER'],
arcz=".1 12 23 37 45 58 78 8.",
arcz_missing="45 58",
arcz_missing="58",
)

def test_excluding_try_except_stranded_else(self):
Expand Down Expand Up @@ -1599,6 +1599,20 @@ def test_formfeed(self):
[1, 6], "", excludes=['assert'],
)

def test_excluded_comprehension_branches(self):
# https://github.com/nedbat/coveragepy/issues/1271
self.check_coverage("""\
x, y = [0], [1]
if x == [2]:
raise NotImplementedError # pragma: NO COVER
if all(_ == __ for _, __ in zip(x, y)):
raise NotImplementedError # pragma: NO COVER
""",
[1,2,4], "", excludes=['#pragma: NO COVER'],
arcz=".1 12 23 24 45 4. -44 4-4",
arcz_missing="4-4",
)


class Py24Test(CoverageTest):
"""Tests of new syntax in Python 2.4."""
Expand Down

0 comments on commit 9209c55

Please sign in to comment.