diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2021-05-22 16:39:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-22 16:39:33 (GMT) |
commit | 220dd80a2671f57486055955d5422163cf73ed33 (patch) | |
tree | 04cc9fcda487050f9978e42f6682d6a51a92f8ec /Lib/test | |
parent | 9e746e3298da36f4e8df0495f91a720f3e54ea33 (diff) | |
download | cpython-220dd80a2671f57486055955d5422163cf73ed33.zip cpython-220dd80a2671f57486055955d5422163cf73ed33.tar.gz cpython-220dd80a2671f57486055955d5422163cf73ed33.tar.bz2 |
bpo-33809: add the TracebackException.print() method (GH-24231)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_traceback.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5bd969d..e9df1ce 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -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): |