summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-11-05 07:23:21 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-11-05 07:23:21 -0400
commit9209c555c7612b4a649edca5db97a04177ee5a9a (patch)
tree2148c2af84186fd1d090b762851fe608647fa5df
parent05562e40c0bea5b89fa9ec2caa0eaa4cebfccd64 (diff)
downloadpython-coveragepy-git-9209c555c7612b4a649edca5db97a04177ee5a9a.tar.gz
fix: don't report branches to exclusions as missing. #1271
-rw-r--r--CHANGES.rst5
-rw-r--r--coverage/results.py3
-rw-r--r--tests/test_coverage.py16
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 8a64f773..9028a0de 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 3daa3e8e..11c4b09b 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -84,13 +84,14 @@ class Analysis:
@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 1ae927bd..d69a0418 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -1492,7 +1492,7 @@ class ExcludeTest(CoverageTest):
""",
[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 @@ class ExcludeTest(CoverageTest):
[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."""