File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -3683,12 +3683,23 @@ class TestMyAppCase(Cmd2TestCase):
36833683 self .__class__ .testfiles = callargs
36843684 sys .argv = [sys .argv [0 ]] # the --test argument upsets unittest.main()
36853685 testcase = TestMyAppCase ()
3686- runner = unittest .TextTestRunner ()
3686+ stream = utils .StdSim (sys .stderr )
3687+ runner = unittest .TextTestRunner (stream = stream )
36873688 test_results = runner .run (testcase )
36883689 if test_results .wasSuccessful ():
3690+ self .decolorized_write (sys .stderr , stream .read ())
36893691 self .poutput ('Tests passed' , color = Fore .LIGHTGREEN_EX )
36903692 else :
3691- self .perror ('Tests failed' , traceback_war = False )
3693+ # Strip off the initial trackeback which isn't particularly useful for end users
3694+ error_str = stream .read ()
3695+ end_of_trace = error_str .find ('AssertionError:' )
3696+ file_offset = error_str [end_of_trace :].find ('File ' )
3697+ start = end_of_trace + file_offset
3698+
3699+ # But print the transcript file name and line number followed by what was expected and what was observed
3700+ self .perror (error_str [start :], traceback_war = False )
3701+
3702+ # Return a failure error code to support automated transcript-based testing
36923703 self .exit_code = - 1
36933704
36943705 def async_alert (self , alert_msg : str , new_prompt : Optional [str ] = None ) -> None : # pragma: no cover
Original file line number Diff line number Diff line change @@ -269,8 +269,8 @@ def test_transcript_failure(request, capsys):
269269 assert sys_exit_code != 0
270270
271271 # Check for the unittest "OK" condition for the 1 test which ran
272- expected_start = "F \n ====================================================================== \n FAIL: runTest "
273- expected_end = "s\n \n FAILED (failures=1)\n Tests failed \n "
272+ expected_start = "File "
273+ expected_end = "s\n \n FAILED (failures=1)\n \n "
274274 _ , err = capsys .readouterr ()
275275 assert err .startswith (expected_start )
276276 assert err .endswith (expected_end )
You can’t perform that action at this time.
0 commit comments