Skip to content

Commit 79087b9

Browse files
committed
fix: don't report branches to missing lines. #1065
Fixes: #1065 Fixes: #955
1 parent b12f189 commit 79087b9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Unreleased
2929
they have been combined. This was requested in `issue 1108`_ and implemented
3030
in `pull request 1110`_. Thanks, Éric Larivière.
3131

32+
- When reporting missing branches in ``coverage report``, branches aren't
33+
reported that jump to missing lines. This adds to the long-standing behavior
34+
of not reporting branches from missing lines. Now branches are only reported
35+
if both the source and destination lines are executed. Closes both `issue
36+
1065`_ and `issue 955`_.
37+
3238
- Minor improvements to the HTML report:
3339

3440
- The state of the line visibility selector buttons is saved in local storage
@@ -41,6 +47,8 @@ Unreleased
4147
will be more likely to understand what's happening, closing `issue 803`_.
4248

4349
.. _issue 803: https://github.com/nedbat/coveragepy/issues/803
50+
.. _issue 955: https://github.com/nedbat/coveragepy/issues/955
51+
.. _issue 1065: https://github.com/nedbat/coveragepy/issues/1065
4452
.. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108
4553
.. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110
4654
.. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123

coverage/results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def format_lines(statements, lines, arcs=None):
312312
line_exits = sorted(arcs)
313313
for line, exits in line_exits:
314314
for ex in sorted(exits):
315-
if line not in lines:
315+
if line not in lines and ex not in lines:
316316
dest = (ex if ex > 0 else "exit")
317317
line_items.append((line, "%d->%s" % (line, dest)))
318318

tests/test_coverage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def test_elif(self):
732732
z = 7
733733
assert x == 3
734734
""",
735-
[1,2,3,4,5,7,8], "4-7", report="7 3 4 1 45% 2->4, 4-7",
735+
[1,2,3,4,5,7,8], "4-7", report="7 3 4 1 45% 4-7",
736736
)
737737
self.check_coverage("""\
738738
a = 1; b = 2; c = 3;
@@ -744,7 +744,7 @@ def test_elif(self):
744744
z = 7
745745
assert y == 5
746746
""",
747-
[1,2,3,4,5,7,8], "3, 7", report="7 2 4 2 64% 2->3, 3, 4->7, 7",
747+
[1,2,3,4,5,7,8], "3, 7", report="7 2 4 2 64% 3, 7",
748748
)
749749
self.check_coverage("""\
750750
a = 1; b = 2; c = 3;
@@ -756,7 +756,7 @@ def test_elif(self):
756756
z = 7
757757
assert z == 7
758758
""",
759-
[1,2,3,4,5,7,8], "3, 5", report="7 2 4 2 64% 2->3, 3, 4->5, 5",
759+
[1,2,3,4,5,7,8], "3, 5", report="7 2 4 2 64% 3, 5",
760760
)
761761

762762
def test_elif_no_else(self):
@@ -768,7 +768,7 @@ def test_elif_no_else(self):
768768
y = 5
769769
assert x == 3
770770
""",
771-
[1,2,3,4,5,6], "4-5", report="6 2 4 1 50% 2->4, 4-5",
771+
[1,2,3,4,5,6], "4-5", report="6 2 4 1 50% 4-5",
772772
)
773773
self.check_coverage("""\
774774
a = 1; b = 2; c = 3;
@@ -778,7 +778,7 @@ def test_elif_no_else(self):
778778
y = 5
779779
assert y == 5
780780
""",
781-
[1,2,3,4,5,6], "3", report="6 1 4 2 70% 2->3, 3, 4->6",
781+
[1,2,3,4,5,6], "3", report="6 1 4 2 70% 3, 4->6",
782782
)
783783

784784
def test_elif_bizarre(self):

tests/test_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def branch(x, y, z):
280280
'Name Stmts Miss Branch BrPart Cover Missing',
281281
'---------------------------------------------------------',
282282
'main.py 1 0 0 0 100%',
283-
'mybranch.py 10 2 8 3 61% 2->4, 4->6, 6->7, 7-8',
283+
'mybranch.py 10 2 8 3 61% 2->4, 4->6, 7-8',
284284
'---------------------------------------------------------',
285285
'TOTAL 11 2 8 3 63%',
286286
]

0 commit comments

Comments
 (0)