mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-33809: add the TracebackException.print() method (GH-24231)
This commit is contained in:
parent
9e746e3298
commit
220dd80a26
4 changed files with 34 additions and 4 deletions
|
|
@ -1378,6 +1378,23 @@ class TestTracebackException(unittest.TestCase):
|
|||
exc = traceback.TracebackException(Exception, Exception("haven"), None)
|
||||
self.assertEqual(list(exc.format()), ["Exception: haven\n"])
|
||||
|
||||
def test_print(self):
|
||||
def f():
|
||||
x = 12
|
||||
try:
|
||||
x/0
|
||||
except Exception:
|
||||
return sys.exc_info()
|
||||
exc = traceback.TracebackException(*f(), capture_locals=True)
|
||||
output = StringIO()
|
||||
exc.print(file=output)
|
||||
self.assertEqual(
|
||||
output.getvalue().split('\n')[-4:],
|
||||
[' x/0',
|
||||
' x = 12',
|
||||
'ZeroDivisionError: division by zero',
|
||||
''])
|
||||
|
||||
|
||||
class MiscTest(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue