diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2014-01-22 23:04:37 +1000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2014-01-22 23:04:37 +1000 |
commit | d58831e6886ce457626448c6c2efd1f4cd05dd3a (patch) | |
tree | 2571c8d98d76f8ed944de9a517c546c53a25cf61 /Lib/test/test_contextlib.py | |
parent | 4a2dbeb0d3067aefab00ba3f43ee1939608323be (diff) | |
parent | 09761e7c9cf984b8164c172fcf9f1a5994402495 (diff) | |
download | cpython-git-d58831e6886ce457626448c6c2efd1f4cd05dd3a.tar.gz |
Merge #20317 from 3.3
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index b8770c828f..f947232176 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -626,6 +626,29 @@ class TestExitStack(unittest.TestCase): else: self.fail("Expected KeyError, but no exception was raised") + def test_exit_exception_with_correct_context(self): + # http://bugs.python.org/issue20317 + @contextmanager + def gets_the_context_right(): + try: + yield 6 + finally: + 1 / 0 + + # The contextmanager already fixes the context, so prior to the + # fix, ExitStack would try to fix it *again* and get into an + # infinite self-referential loop + try: + with ExitStack() as stack: + stack.enter_context(gets_the_context_right()) + stack.enter_context(gets_the_context_right()) + stack.enter_context(gets_the_context_right()) + except ZeroDivisionError as exc: + self.assertIsInstance(exc.__context__, ZeroDivisionError) + self.assertIsInstance(exc.__context__.__context__, ZeroDivisionError) + self.assertIsNone(exc.__context__.__context__.__context__) + + def test_body_exception_suppress(self): def suppress_exc(*exc_details): return True |