Skip to content

Commit

Permalink
fix: don't report branches to missing lines. #1065
Browse files Browse the repository at this point in the history
Fixes: #1065
Fixes: #955
  • Loading branch information
nedbat committed Feb 28, 2021
1 parent b12f189 commit 79087b9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion coverage/results.py
Expand Up @@ -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)))

Expand Down
10 changes: 5 additions & 5 deletions tests/test_coverage.py
Expand Up @@ -732,7 +732,7 @@ def test_elif(self):
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;
Expand All @@ -744,7 +744,7 @@ def test_elif(self):
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;
Expand All @@ -756,7 +756,7 @@ def test_elif(self):
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):
Expand All @@ -768,7 +768,7 @@ def test_elif_no_else(self):
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;
Expand All @@ -778,7 +778,7 @@ def test_elif_no_else(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_summary.py
Expand Up @@ -280,7 +280,7 @@ def branch(x, y, z):
'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%',
]
Expand Down

0 comments on commit 79087b9

Please sign in to comment.