diff --git a/AUTHORS b/AUTHORS index ad86f89..91a946e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,2 @@ Robert Collins +Berker Peksag diff --git a/traceback2/__init__.py b/traceback2/__init__.py index 88fcaaf..7fdeb36 100644 --- a/traceback2/__init__.py +++ b/traceback2/__init__.py @@ -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,7 +591,8 @@ class TracebackException: for line in self.__context__.format(chain=chain): yield line yield _context_message - yield u('Traceback (most recent call last):\n') + if self.exc_traceback is not None: + yield u('Traceback (most recent call last):\n') for line in self.stack.format(): yield line for line in self.format_exception_only(): diff --git a/traceback2/tests/test_traceback.py b/traceback2/tests/test_traceback.py index 2a933b5..3430a4d 100644 --- a/traceback2/tests/test_traceback.py +++ b/traceback2/tests/test_traceback.py @@ -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")