Skip to content

Commit 048ee2d

Browse files
authored
pythongh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (python#130342)
1 parent 417372b commit 048ee2d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Lib/test/test_traceback.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,10 @@ def test_print_exception_exc(self):
511511
self.assertEqual(output.getvalue(), "Exception: projector\n")
512512

513513
def test_print_last(self):
514-
self.assertIsNone(getattr(sys, "last_exc", None))
515-
try:
516-
sys.last_exc = ValueError(42)
514+
with support.swap_attr(sys, 'last_exc', ValueError(42)):
517515
output = StringIO()
518516
traceback.print_last(file=output)
519517
self.assertEqual(output.getvalue(), "ValueError: 42\n")
520-
finally:
521-
sys.last_exc = None
522518

523519
def test_format_exception_exc(self):
524520
e = Exception("projector")

0 commit comments

Comments
 (0)