mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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.
This commit is contained in:
parent
c19bb3279c
commit
c3f417dc47
3 changed files with 20 additions and 1 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue