From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 20 Feb 2025 02:00:49 +0000 (+0100) Subject: [3.13] gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329) (#130330) X-Git-Tag: v3.13.3~250 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46237d19d9a744920a5f2795be642a663bcd843f;p=thirdparty%2FPython%2Fcpython.git [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 c718c6be0f82af5eb0e57615ce323242155ff014) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5d24f6850d01..321ee2294b9f 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -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")