Skip to content

Commit d103357

Browse files
[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 048ee2d) Co-authored-by: Irit Katriel <[email protected]>
1 parent 178b2ec commit d103357

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
@@ -517,14 +517,10 @@ def test_print_exception_exc(self):
517517
self.assertEqual(output.getvalue(), "Exception: projector\n")
518518

519519
def test_print_last(self):
520-
self.assertIsNone(getattr(sys, "last_exc", None))
521-
try:
522-
sys.last_exc = ValueError(42)
520+
with support.swap_attr(sys, 'last_exc', ValueError(42)):
523521
output = StringIO()
524522
traceback.print_last(file=output)
525523
self.assertEqual(output.getvalue(), "ValueError: 42\n")
526-
finally:
527-
sys.last_exc = None
528524

529525
def test_format_exception_exc(self):
530526
e = Exception("projector")

0 commit comments

Comments
 (0)