]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-130250: use support.swap_attr() in test and don't assume we're beginning...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 20 Feb 2025 11:45:42 +0000 (12:45 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Feb 2025 11:45:42 +0000 (11:45 +0000)
gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (GH-130342)
(cherry picked from commit 048ee2d5ec761296ef67f5c59aee1f24408b12db)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Lib/test/test_traceback.py

index 0b8462dfd5265ff508046974157e56fb2f6054bb..8300e511cf42328453d07238254ed78dbe308d91 100644 (file)
@@ -329,14 +329,10 @@ class TracebackCases(unittest.TestCase):
         self.assertEqual(output.getvalue(), "Exception: projector\n")
 
     def test_print_last(self):
-        self.assertIsNone(getattr(sys, "last_exc", None))
-        try:
-            sys.last_exc = ValueError(42)
+        with support.swap_attr(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")