diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2025-02-20 11:29:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-20 11:29:18 +0000 |
commit | 048ee2d5ec761296ef67f5c59aee1f24408b12db (patch) | |
tree | ad1a59ae0ee4ba8216866d50a0e54f62ca6bebf9 | |
parent | 417372bd43ecb61a848eadb3ce142f0ed3441b49 (diff) | |
download | cpython-048ee2d5ec761296ef67f5c59aee1f24408b12db.tar.gz cpython-048ee2d5ec761296ef67f5c59aee1f24408b12db.zip |
gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (#130342)
-rw-r--r-- | Lib/test/test_traceback.py | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 266a1ec0490..68c4fa117a9 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -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") |