summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-18 21:56:14 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-18 21:56:14 -0500
commitc3fd76b5c7902dc345e83854b0a9db4e8c1475a1 (patch)
tree9058b3f0e3105114239969d333abc93db25c24ee
parent18649f5d03c962211c3a157896aee5053992594a (diff)
downloadpython-coveragepy-c3fd76b5c7902dc345e83854b0a9db4e8c1475a1.tar.gz
Clean up #493 fix
-rw-r--r--CHANGES.rst6
-rw-r--r--CONTRIBUTORS.txt4
-rw-r--r--coverage/parser.py2
-rw-r--r--tests/test_arcs.py33
4 files changed, 20 insertions, 25 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 81b1c99..98cdbea 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,6 +18,11 @@ Unreleased
data, leaving you with an empty .coverage data file. Fixes issues
`issue 525`_, `issue 412`_, `issue 516`_, and probably `issue 511`_.
+- Branch coverage could misunderstand a finally clause on a try block that
+ never continued on to the following statement, as described in `issue 493`_.
+ This is now fixed. Thanks to Joe Doherty for the report and Loïc Dachary for
+ the fix.
+
- Options can now be read from a tox.ini file, if any. Like setup.cfg, sections
are prefixed with "coverage:", so ``[run]`` options will be read from the
``[coverage:run]`` section of tox.ini. Implements part of `issue 519`_.
@@ -85,6 +90,7 @@ Unreleased
.. _issue 265: https://bitbucket.org/ned/coveragepy/issues/265/when-using-source-include-is-silently
.. _issue 412: https://bitbucket.org/ned/coveragepy/issues/412/coverage-combine-should-error-if-no
+.. _issue 493: https://bitbucket.org/ned/coveragepy/issues/493/confusing-branching-failure
.. _issue 505: https://bitbucket.org/ned/coveragepy/issues/505/use-canonical-filename-for-debounce
.. _issue 514: https://bitbucket.org/ned/coveragepy/issues/514/path-to-problem-file-not-reported-when
.. _issue 510: https://bitbucket.org/ned/coveragepy/issues/510/erase-still-needed-in-42
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index a7e7b85..a3c5ffb 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -1,7 +1,8 @@
Coverage.py was originally written by Gareth Rees, and since 2004 has been
extended and maintained by Ned Batchelder.
-Other contributions have been made by:
+Other contributions, including writing code, updating docs, and submitting
+useful bug reports, have been made by:
Adi Roiban
Alex Gaynor
@@ -45,6 +46,7 @@ Imri Goldberg
Ionel Cristian Mărieș
JT Olds
Jessamyn Smith
+Joe Doherty
Jon Chappell
Joseph Tate
Josh Williams
diff --git a/coverage/parser.py b/coverage/parser.py
index e75694f..db8f65f 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -893,6 +893,8 @@ class AstArcAnalyzer(object):
return_exits = self._combine_finally_starts(try_block.return_from, final_exits)
self.process_return_exits(return_exits)
if exits:
+ # The finally clause's exits are only exits for the try block
+ # as a whole if the try block had some exits to begin with.
exits = final_exits
return exits
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index a245e21..5baf947 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -762,34 +762,19 @@ class ExceptionArcTest(CoverageTest):
def test_return_finally(self):
self.check_coverage("""\
a = [1]
- def func():
- try:
- return 10
- finally:
- a.append(6)
-
- assert func() == 10
- assert a == [1, 6]
- """,
- arcz=".1 12 28 89 9. -23 34 46 6-2",
- )
-
- def test_return_finally_before_return(self):
- self.check_coverage("""\
- a = []
def check_token(data):
if data:
try:
- return 1
+ return 5
finally:
- a.append(1)
- return 2
- assert 2 == check_token(False)
- assert [] == a
- assert 1 == check_token(True)
- assert [1] == a
- """,
- arcz=".1 12 29 9A AB BC C-1 -23 34 45 57 7-2 38 8-2",
+ a.append(7)
+ return 8
+ assert check_token(False) == 8
+ assert a == [1]
+ assert check_token(True) == 5
+ assert a == [1, 7]
+ """,
+ arcz=".1 12 29 9A AB BC C-1 -23 34 45 57 7-2 38 8-2",
)
def test_except_jump_finally(self):