diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-02 16:14:35 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-02 16:14:35 -0500 |
commit | 3440e214df5ddd0f507ecd76c2350eb8d9dd6a75 (patch) | |
tree | 269b38aafeca25ebe8dac091a5c246b710bc4aaf | |
parent | 9ee958be82e8e4f1cb958862cb29fa5b3d5f2523 (diff) | |
download | python-coveragepy-git-3440e214df5ddd0f507ecd76c2350eb8d9dd6a75.tar.gz |
Support returning through a finally
--HG--
branch : ast-branch
-rw-r--r-- | coverage/parser.py | 8 | ||||
-rw-r--r-- | tests/test_arcs.py | 15 |
2 files changed, 19 insertions, 4 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 44cb1559..d85f0b57 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -426,8 +426,6 @@ class AstArcAnalyzer(object): # TODO: listcomps hidden in lists: x = [[i for i in range(10)]] # TODO: multi-line listcomps # TODO: nested function definitions - # TODO: multiple `except` clauses - # TODO: return->finally def process_break_exits(self, exits): for block in self.blocks(): @@ -467,8 +465,10 @@ class AstArcAnalyzer(object): def process_return_exits(self, exits): for block in self.blocks(): - # TODO: need a check here for TryBlock - if isinstance(block, FunctionBlock): + if isinstance(block, TryBlock) and block.final_start: + block.return_from.update(exits) + break + elif isinstance(block, FunctionBlock): # TODO: what if there is no enclosing function? for exit in exits: self.arcs.add((exit, -block.start)) diff --git a/tests/test_arcs.py b/tests/test_arcs.py index cd3aafff..88442049 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -682,6 +682,21 @@ class ExceptionArcTest(CoverageTest): arcz_unpredicted="45 AB", ) + 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. .3 34 46 6-2", + ) + class YieldTest(CoverageTest): """Arc tests for generators.""" |