mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
PyErr_Print can leave sys.last_traceback hanging around; kill it
This commit is contained in:
parent
8af4919b37
commit
47afc2af79
1 changed files with 8 additions and 10 deletions
|
|
@ -265,28 +265,26 @@ class DisTests(unittest.TestCase):
|
|||
self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes)
|
||||
|
||||
def test_dis_none(self):
|
||||
try:
|
||||
del sys.last_traceback
|
||||
except AttributeError:
|
||||
pass
|
||||
self.assertRaises(RuntimeError, dis.dis, None)
|
||||
|
||||
def test_dis_object(self):
|
||||
self.assertRaises(TypeError, dis.dis, object())
|
||||
|
||||
def test_dis_traceback(self):
|
||||
not_defined = object()
|
||||
tb = None
|
||||
old = getattr(sys, 'last_traceback', not_defined)
|
||||
|
||||
def cleanup():
|
||||
if old is not not_defined:
|
||||
sys.last_traceback = old
|
||||
else:
|
||||
del sys.last_traceback
|
||||
try:
|
||||
del sys.last_traceback
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
1/0
|
||||
except Exception as e:
|
||||
tb = e.__traceback__
|
||||
sys.last_traceback = tb
|
||||
self.addCleanup(cleanup)
|
||||
|
||||
tb_dis = self.get_disassemble_as_string(tb.tb_frame.f_code, tb.tb_lasti)
|
||||
self.do_disassembly_test(None, tb_dis)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue