]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-130250: fix cleanup in test (impacts refleaks runs) (GH-130329) (#130331)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 20 Feb 2025 01:54:37 +0000 (02:54 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Feb 2025 01:54:37 +0000 (01:54 +0000)
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>
Lib/test/test_traceback.py

index be431cc5631fbf50c044f8290890c5c5b9e76326..0b8462dfd5265ff508046974157e56fb2f6054bb 100644 (file)
@@ -330,10 +330,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")