diff options
author | Andrew Kuchling <amk@amk.ca> | 2013-09-15 22:15:56 (GMT) |
---|---|---|
committer | Andrew Kuchling <amk@amk.ca> | 2013-09-15 22:15:56 (GMT) |
commit | 173a157e725579eec1f28f8c9d53d6761ba6c79f (patch) | |
tree | 98be7afea0a4f929f07193d94ffe86cc0e7739e0 /Lib/test/test_traceback.py | |
parent | 8408dc581e2baaa306b57f14486cfa013fd68c68 (diff) | |
download | cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.zip cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.tar.gz cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.tar.bz2 |
#1565525: Add traceback.clear_frames() helper function to clear locals ref'd by a traceback
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r-- | Lib/test/test_traceback.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 66a12bf..96ef951 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -388,6 +388,36 @@ class CExcReportingTests(BaseExceptionReportingTests, unittest.TestCase): return s.getvalue() +class MiscTracebackCases(unittest.TestCase): + # + # Check non-printing functions in traceback module + # + + def test_clear(self): + def outer(): + middle() + def middle(): + inner() + def inner(): + i = 1 + 1/0 + + try: + outer() + except: + type_, value, tb = sys.exc_info() + + # Initial assertion: there's one local in the inner frame. + inner_frame = tb.tb_next.tb_next.tb_next.tb_frame + self.assertEqual(len(inner_frame.f_locals), 1) + + # Clear traceback frames + traceback.clear_frames(tb) + + # Local variable dict should now be empty. + self.assertEqual(len(inner_frame.f_locals), 0) + + def test_main(): run_unittest(__name__) |