]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130250: use support.swap_attr() in test and don't assume we're beginning with...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Thu, 20 Feb 2025 11:29:18 +0000 (11:29 +0000)
committerGitHub <noreply@github.com>
Thu, 20 Feb 2025 11:29:18 +0000 (11:29 +0000)
Lib/test/test_traceback.py

index 266a1ec04908fc203003712c3ef8f15c734b42e4..68c4fa117a90f55641fba32de65cce012e4ac9d9 100644 (file)
@@ -511,14 +511,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")