diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2021-01-12 22:14:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 22:14:27 (GMT) |
commit | 6dfd1734f5b230bb8fbd2a9df806c1333b6652a8 (patch) | |
tree | b06c2c646dbe1fb7ad824044a02b9999dc2b3194 /Lib/test | |
parent | 0f66498fd8ee8644be6df963b86a1523f6069ddd (diff) | |
download | cpython-6dfd1734f5b230bb8fbd2a9df806c1333b6652a8.zip cpython-6dfd1734f5b230bb8fbd2a9df806c1333b6652a8.tar.gz cpython-6dfd1734f5b230bb8fbd2a9df806c1333b6652a8.tar.bz2 |
bpo-42848: remove recursion from TracebackException (GH-24158)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_traceback.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index abb5762..07555a0 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1148,6 +1148,31 @@ class TestTracebackException(unittest.TestCase): self.assertEqual(exc_info[0], exc.exc_type) self.assertEqual(str(exc_info[1]), str(exc)) + def test_long_context_chain(self): + def f(): + try: + 1/0 + except: + f() + + try: + f() + except RecursionError: + exc_info = sys.exc_info() + else: + self.fail("Exception not raised") + + te = traceback.TracebackException(*exc_info) + res = list(te.format()) + + # many ZeroDiv errors followed by the RecursionError + self.assertGreater(len(res), sys.getrecursionlimit()) + self.assertGreater( + len([l for l in res if 'ZeroDivisionError:' in l]), + sys.getrecursionlimit() * 0.5) + self.assertIn( + "RecursionError: maximum recursion depth exceeded", res[-1]) + def test_no_refs_to_exception_and_traceback_objects(self): try: 1/0 |