diff options
| author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-08-31 20:42:08 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-31 20:42:08 (GMT) |
| commit | 863154c9292e70c5a8a1a3f22ef4ee42e2304281 (patch) | |
| tree | 494d7e167c6d21600a6db95642af773a1e4eeb46 /Lib/test/test_traceback.py | |
| parent | 22fe0eb13c3441b71b60aaea0e7fe289a29783da (diff) | |
| download | cpython-863154c9292e70c5a8a1a3f22ef4ee42e2304281.zip cpython-863154c9292e70c5a8a1a3f22ef4ee42e2304281.tar.gz cpython-863154c9292e70c5a8a1a3f22ef4ee42e2304281.tar.bz2 | |
bpo-31299: make it possible to filter out frames from tracebacks (GH-28067)
Diffstat (limited to 'Lib/test/test_traceback.py')
| -rw-r--r-- | Lib/test/test_traceback.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5d48e9d..d1967aa 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1514,6 +1514,34 @@ class TestStack(unittest.TestCase): s.format(), [f'{__file__}:{some_inner.__code__.co_firstlineno + 1}']) + def test_dropping_frames(self): + def f(): + 1/0 + + def g(): + try: + f() + except: + return sys.exc_info() + + exc_info = g() + + class Skip_G(traceback.StackSummary): + def format_frame(self, frame): + if frame.name == 'g': + return None + return super().format_frame(frame) + + stack = Skip_G.extract( + traceback.walk_tb(exc_info[2])).format() + + self.assertEqual(len(stack), 1) + lno = f.__code__.co_firstlineno + 1 + self.assertEqual( + stack[0], + f' File "{__file__}", line {lno}, in f\n 1/0\n' + ) + class TestTracebackException(unittest.TestCase): |
