[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 c718c6be0f)

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

View file

@ -330,10 +330,13 @@ def test_print_exception_exc(self):
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")