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
37c5f154f0
commit
2218e9cf14
1
AUTHORS
1
AUTHORS
@ -1 +1,2 @@
|
||||
Robert Collins <rbtcollins@hp.com>
|
||||
Berker Peksag <berker.peksag@gmail.com>
|
||||
|
@ -465,6 +465,7 @@ class TracebackException:
|
||||
_seen=_seen)
|
||||
else:
|
||||
context = None
|
||||
self.exc_traceback = exc_traceback
|
||||
self.__cause__ = cause
|
||||
self.__context__ = context
|
||||
self.__suppress_context__ = \
|
||||
@ -590,6 +591,7 @@ class TracebackException:
|
||||
for line in self.__context__.format(chain=chain):
|
||||
yield line
|
||||
yield _context_message
|
||||
if self.exc_traceback is not None:
|
||||
yield u('Traceback (most recent call last):\n')
|
||||
for line in self.stack.format():
|
||||
yield line
|
||||
|
@ -793,6 +793,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()), [u("Exception: haven\n")])
|
||||
|
||||
def test_syntax_no_extras(self):
|
||||
linecache.updatecache('/foo.py', fake_module)
|
||||
e = SyntaxError("uh oh")
|
||||
|
Loading…
Reference in New Issue
Block a user