[3.13] gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329) (#130330)

gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329)
(cherry picked from commit c718c6be0f)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-02-20 03:00:49 +01:00 committed by GitHub
parent d172415a4e
commit 46237d19d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -518,10 +518,13 @@ class TracebackCases(unittest.TestCase):
def test_print_last(self):
self.assertIsNone(getattr(sys, "last_exc", None))
sys.last_exc = ValueError(42)
output = StringIO()
traceback.print_last(file=output)
self.assertEqual(output.getvalue(), "ValueError: 42\n")
try:
sys.last_exc = ValueError(42)
output = StringIO()
traceback.print_last(file=output)
self.assertEqual(output.getvalue(), "ValueError: 42\n")
finally:
sys.last_exc = None
def test_format_exception_exc(self):
e = Exception("projector")