From 79087b9f9e561bec1654ee80f143c4754641e81f Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 28 Feb 2021 10:46:11 -0500 Subject: [PATCH] fix: don't report branches to missing lines. #1065 Fixes: #1065 Fixes: #955 --- CHANGES.rst | 8 ++++++++ coverage/results.py | 2 +- tests/test_coverage.py | 10 +++++----- tests/test_summary.py | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 82f174dd3..1dd57b034 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 7f9893618..4916864df 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 00648c189..30a8edc5a 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -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; @@ -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; @@ -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): @@ -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; @@ -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): diff --git a/tests/test_summary.py b/tests/test_summary.py index 3be1e8690..8596c45c4 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -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%', ]