output = traceback.format_exception_only(Exception("projector"))
self.assertEqual(output, ["Exception: projector\n"])
+ def test_exception_is_None(self):
+ NONE_EXC_STRING = 'NoneType: None\n'
+ excfile = StringIO()
+ traceback.print_exception(None, None, None, file=excfile)
+ self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
+
+ excfile = StringIO()
+ traceback.print_exc(None, file=excfile)
+ self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
+
+ self.assertEqual(traceback.format_exc(None), NONE_EXC_STRING)
+ self.assertEqual(
+ traceback.format_exception(None, None, None), [NONE_EXC_STRING])
+ self.assertEqual(
+ traceback.format_exception_only(None), [NONE_EXC_STRING])
+ self.assertEqual(
+ traceback.format_exception_only(None, None), [NONE_EXC_STRING])
+
class TracebackFormatTests(unittest.TestCase):
cause = None
if compact:
- need_context = cause is None and not e.__suppress_context__
+ need_context = (cause is None and
+ e is not None and
+ not e.__suppress_context__)
else:
need_context = True
if (e and e.__context__ is not None