Skip to content

Commit 4fb2bb6

Browse files
[3.12] gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329) (#130331)
gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329) (cherry picked from commit c718c6b) Co-authored-by: Irit Katriel <[email protected]>
1 parent 8d58070 commit 4fb2bb6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/test/test_traceback.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,13 @@ def test_print_exception_exc(self):
330330

331331
def test_print_last(self):
332332
self.assertIsNone(getattr(sys, "last_exc", None))
333-
sys.last_exc = ValueError(42)
334-
output = StringIO()
335-
traceback.print_last(file=output)
336-
self.assertEqual(output.getvalue(), "ValueError: 42\n")
333+
try:
334+
sys.last_exc = ValueError(42)
335+
output = StringIO()
336+
traceback.print_last(file=output)
337+
self.assertEqual(output.getvalue(), "ValueError: 42\n")
338+
finally:
339+
sys.last_exc = None
337340

338341
def test_format_exception_exc(self):
339342
e = Exception("projector")

0 commit comments

Comments
 (0)