diff --git a/CHANGES.rst b/CHANGES.rst index 8a64f7737..9028a0de8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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: diff --git a/coverage/results.py b/coverage/results.py index 3daa3e8e2..11c4b09b4 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -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) diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 1ae927bdd..d69a04180 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -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): @@ -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."""