diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-07-24 14:36:21 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-07-24 14:36:21 (GMT) |
commit | c3f417dc47b3a9564608c98cd176c530d9ebdf09 (patch) | |
tree | 6a1c894fe313dcbcf82a4425704ad580bd9b45f6 /Lib/test/test_traceback.py | |
parent | c19bb3279cbb42c84a24255db48ee2d385bb8167 (diff) | |
download | cpython-c3f417dc47b3a9564608c98cd176c530d9ebdf09.zip cpython-c3f417dc47b3a9564608c98cd176c530d9ebdf09.tar.gz cpython-c3f417dc47b3a9564608c98cd176c530d9ebdf09.tar.bz2 |
Issue #24695: Fix a regression in traceback.print_exception()
If exc_traceback is None we shouldn't print a traceback header
like described in the documentation.
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r-- | Lib/test/test_traceback.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index e8c4d74..641a2df 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -209,6 +209,13 @@ class SyntaxTracebackCases(unittest.TestCase): b'ZeroDivisionError: division by zero'] self.assertEqual(stderr.splitlines(), expected) + def test_print_exception(self): + output = StringIO() + traceback.print_exception( + Exception, Exception("projector"), None, file=output + ) + self.assertEqual(output.getvalue(), "Exception: projector\n") + class TracebackFormatTests(unittest.TestCase): @@ -848,6 +855,12 @@ class TestTracebackException(unittest.TestCase): exc = traceback.TracebackException(Exception, e, tb) self.assertEqual(exc.stack[0].locals, None) + def test_traceback_header(self): + # do not print a traceback header if exc_traceback is None + # see issue #24695 + exc = traceback.TracebackException(Exception, Exception("haven"), None) + self.assertEqual(list(exc.format()), ["Exception: haven\n"]) + class MiscTest(unittest.TestCase): |