Skip to content

Commit 96a914a

Browse files
[3.12] gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (GH-130342) (#130345)
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 048ee2d) Co-authored-by: Irit Katriel <[email protected]>
1 parent b259b75 commit 96a914a

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Lib/test/test_traceback.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,10 @@ def test_print_exception_exc(self):
329329
self.assertEqual(output.getvalue(), "Exception: projector\n")
330330

331331
def test_print_last(self):
332-
self.assertIsNone(getattr(sys, "last_exc", None))
333-
try:
334-
sys.last_exc = ValueError(42)
332+
with support.swap_attr(sys, 'last_exc', ValueError(42)):
335333
output = StringIO()
336334
traceback.print_last(file=output)
337335
self.assertEqual(output.getvalue(), "ValueError: 42\n")
338-
finally:
339-
sys.last_exc = None
340336

341337
def test_format_exception_exc(self):
342338
e = Exception("projector")

0 commit comments

Comments
 (0)