File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -364,11 +364,7 @@ def _format_exception_only(
364364 )
365365 )
366366
367- try :
368- assert hasattr (value , "msg" )
369- s = value .msg
370- except Exception :
371- s = self ._some_str (value )
367+ s = self ._some_str (value )
372368 if s :
373369 output_list .append (
374370 theme_table [self ._theme_name ].format (
Original file line number Diff line number Diff line change @@ -437,6 +437,20 @@ def test_plain_reports_notes(self):
437437 ip .run_cell ("%xmode Verbose" )
438438
439439
440+ class ExceptionMessagePreferenceTest (unittest .TestCase ):
441+ """
442+ Test that exception string representation is preferred over .msg attribute
443+ for non-SyntaxError exceptions in %xmode plain.
444+ """
445+
446+ def test_jsondecodeerror_message (self ):
447+ cell = "import json;json.loads('{\" a\" : }')"
448+ expected = "JSONDecodeError: Expecting value: line 1 column 7 (char 6)"
449+ ip .run_cell ("%xmode plain" )
450+ with tt .AssertPrints (expected ):
451+ ip .run_cell (cell )
452+ ip .run_cell ("%xmode context" )
453+
440454# ----------------------------------------------------------------------------
441455
442456
You can’t perform that action at this time.
0 commit comments