summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-02-28 10:46:11 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-02-28 11:02:15 -0500
commit79087b9f9e561bec1654ee80f143c4754641e81f (patch)
tree618599d916054cb89becb3f6c3f36c22b01984e3
parentb12f189e8ed34b31438b8cca19133b74f7d67f90 (diff)
downloadpython-coveragepy-git-79087b9f9e561bec1654ee80f143c4754641e81f.tar.gz
fix: don't report branches to missing lines. #1065
Fixes: #1065 Fixes: #955
-rw-r--r--CHANGES.rst8
-rw-r--r--coverage/results.py2
-rw-r--r--tests/test_coverage.py10
-rw-r--r--tests/test_summary.py2
4 files changed, 15 insertions, 7 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 82f174dd..1dd57b03 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -29,6 +29,12 @@ Unreleased
they have been combined. This was requested in `issue 1108`_ and implemented
in `pull request 1110`_. Thanks, Éric Larivière.
+- When reporting missing branches in ``coverage report``, branches aren't
+ reported that jump to missing lines. This adds to the long-standing behavior
+ of not reporting branches from missing lines. Now branches are only reported
+ if both the source and destination lines are executed. Closes both `issue
+ 1065`_ and `issue 955`_.
+
- Minor improvements to the HTML report:
- The state of the line visibility selector buttons is saved in local storage
@@ -41,6 +47,8 @@ Unreleased
will be more likely to understand what's happening, closing `issue 803`_.
.. _issue 803: https://github.com/nedbat/coveragepy/issues/803
+.. _issue 955: https://github.com/nedbat/coveragepy/issues/955
+.. _issue 1065: https://github.com/nedbat/coveragepy/issues/1065
.. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108
.. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110
.. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123
diff --git a/coverage/results.py b/coverage/results.py
index 7f989361..4916864d 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -312,7 +312,7 @@ def format_lines(statements, lines, arcs=None):
line_exits = sorted(arcs)
for line, exits in line_exits:
for ex in sorted(exits):
- if line not in lines:
+ if line not in lines and ex not in lines:
dest = (ex if ex > 0 else "exit")
line_items.append((line, "%d->%s" % (line, dest)))
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 00648c18..30a8edc5 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -732,7 +732,7 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert x == 3
""",
- [1,2,3,4,5,7,8], "4-7", report="7 3 4 1 45% 2->4, 4-7",
+ [1,2,3,4,5,7,8], "4-7", report="7 3 4 1 45% 4-7",
)
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -744,7 +744,7 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert y == 5
""",
- [1,2,3,4,5,7,8], "3, 7", report="7 2 4 2 64% 2->3, 3, 4->7, 7",
+ [1,2,3,4,5,7,8], "3, 7", report="7 2 4 2 64% 3, 7",
)
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -756,7 +756,7 @@ class CompoundStatementTest(CoverageTest):
z = 7
assert z == 7
""",
- [1,2,3,4,5,7,8], "3, 5", report="7 2 4 2 64% 2->3, 3, 4->5, 5",
+ [1,2,3,4,5,7,8], "3, 5", report="7 2 4 2 64% 3, 5",
)
def test_elif_no_else(self):
@@ -768,7 +768,7 @@ class CompoundStatementTest(CoverageTest):
y = 5
assert x == 3
""",
- [1,2,3,4,5,6], "4-5", report="6 2 4 1 50% 2->4, 4-5",
+ [1,2,3,4,5,6], "4-5", report="6 2 4 1 50% 4-5",
)
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -778,7 +778,7 @@ class CompoundStatementTest(CoverageTest):
y = 5
assert y == 5
""",
- [1,2,3,4,5,6], "3", report="6 1 4 2 70% 2->3, 3, 4->6",
+ [1,2,3,4,5,6], "3", report="6 1 4 2 70% 3, 4->6",
)
def test_elif_bizarre(self):
diff --git a/tests/test_summary.py b/tests/test_summary.py
index 3be1e869..8596c45c 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -280,7 +280,7 @@ class SummaryTest(UsingModulesMixin, CoverageTest):
'Name Stmts Miss Branch BrPart Cover Missing',
'---------------------------------------------------------',
'main.py 1 0 0 0 100%',
- 'mybranch.py 10 2 8 3 61% 2->4, 4->6, 6->7, 7-8',
+ 'mybranch.py 10 2 8 3 61% 2->4, 4->6, 7-8',
'---------------------------------------------------------',
'TOTAL 11 2 8 3 63%',
]