diff options
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 4 | ||||
-rw-r--r-- | coverage/parser.py | 2 | ||||
-rw-r--r-- | tests/test_arcs.py | 33 |
4 files changed, 20 insertions, 25 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 81b1c998..98cdbea6 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 a7e7b858..a3c5ffb1 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 e75694f9..db8f65f3 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 a245e214..5baf9476 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): |