mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-130250: use support.swap_attr() in test and don't assume we're beginning with a clean system state (#130342)
This commit is contained in:
parent
417372bd43
commit
048ee2d5ec
1 changed files with 1 additions and 5 deletions
|
@ -511,14 +511,10 @@ class TracebackCases(unittest.TestCase):
|
||||||
self.assertEqual(output.getvalue(), "Exception: projector\n")
|
self.assertEqual(output.getvalue(), "Exception: projector\n")
|
||||||
|
|
||||||
def test_print_last(self):
|
def test_print_last(self):
|
||||||
self.assertIsNone(getattr(sys, "last_exc", None))
|
with support.swap_attr(sys, 'last_exc', ValueError(42)):
|
||||||
try:
|
|
||||||
sys.last_exc = ValueError(42)
|
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
traceback.print_last(file=output)
|
traceback.print_last(file=output)
|
||||||
self.assertEqual(output.getvalue(), "ValueError: 42\n")
|
self.assertEqual(output.getvalue(), "ValueError: 42\n")
|
||||||
finally:
|
|
||||||
sys.last_exc = None
|
|
||||||
|
|
||||||
def test_format_exception_exc(self):
|
def test_format_exception_exc(self):
|
||||||
e = Exception("projector")
|
e = Exception("projector")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue