From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 20 Feb 2025 11:52:06 +0000 (+0100) Subject: [3.13] gh-130250: use support.swap_attr() in test and don't assume we're beginning... X-Git-Tag: v3.13.3~244 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d103357785e239edd1a3b0881fff3d6682a7bfc2;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (GH-130342) (#130344) 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> --- diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 321ee2294b9f..d104402f2fd6 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -517,14 +517,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")