@@ -162,14 +162,16 @@ def were_doctests_with_optional_tag_run(self, tag):
162
162
return True
163
163
return False
164
164
165
- def report_head (self , source ):
165
+ def report_head (self , source , fail_msg = None ):
166
166
"""
167
- Return the " sage -t [options] file.py" line as string.
167
+ Return the `` sage -t [options] file.py`` line as string.
168
168
169
169
INPUT:
170
170
171
171
- ``source`` -- a source from :mod:`sage.doctest.sources`
172
172
173
+ - ``fail_msg`` -- ``None`` or a string
174
+
173
175
EXAMPLES::
174
176
175
177
sage: from sage.doctest.reporting import DocTestReporter
@@ -190,6 +192,8 @@ def report_head(self, source):
190
192
sage: DD.long = True
191
193
sage: print(DTR.report_head(FDS))
192
194
sage -t --long .../sage/doctest/reporting.py
195
+ sage: print(DTR.report_head(FDS, "Failed by self-sabotage"))
196
+ sage -t --long .../sage/doctest/reporting.py # Failed by self-sabotage
193
197
"""
194
198
cmd = "sage -t"
195
199
if self .controller .options .long :
@@ -206,6 +210,13 @@ def report_head(self, source):
206
210
if environment != "sage.repl.ipython_kernel.all_jupyter" :
207
211
cmd += f" --environment={ environment } "
208
212
cmd += " " + source .printpath
213
+ baseline = self .controller .source_baseline (source )
214
+ if fail_msg :
215
+ cmd += " # " + fail_msg
216
+ if baseline .get ('failed' , False ):
217
+ if not fail_msg :
218
+ cmd += " #"
219
+ cmd += " [failed in baseline]"
209
220
return cmd
210
221
211
222
def report (self , source , timeout , return_code , results , output , pid = None ):
@@ -420,12 +431,10 @@ def report(self, source, timeout, return_code, results, output, pid=None):
420
431
fail_msg += " (and interrupt failed)"
421
432
else :
422
433
fail_msg += " (with %s after interrupt)" % signal_name (sig )
423
- if baseline .get ('failed' , False ):
424
- fail_msg += " [failed in baseline]"
425
434
log (" %s\n %s\n Tests run before %s timed out:" % (fail_msg , "*" * 70 , process_name ))
426
435
log (output )
427
436
log ("*" * 70 )
428
- postscript ['lines' ].append (cmd + " # %s" % fail_msg )
437
+ postscript ['lines' ].append (self . report_head ( source , fail_msg ) )
429
438
stats [basename ] = {"failed" : True , "walltime" : 1e6 , "ntests" : ntests }
430
439
if not baseline .get ('failed' , False ):
431
440
self .error_status |= 4
@@ -436,12 +445,10 @@ def report(self, source, timeout, return_code, results, output, pid=None):
436
445
fail_msg = "Killed due to %s" % signal_name (- return_code )
437
446
if ntests > 0 :
438
447
fail_msg += " after testing finished"
439
- if baseline .get ('failed' , False ):
440
- fail_msg += " [failed in baseline]"
441
448
log (" %s\n %s\n Tests run before %s failed:" % (fail_msg ,"*" * 70 , process_name ))
442
449
log (output )
443
450
log ("*" * 70 )
444
- postscript ['lines' ].append (cmd + " # %s" % fail_msg )
451
+ postscript ['lines' ].append (self . report_head ( source , fail_msg ) )
445
452
stats [basename ] = {"failed" : True , "walltime" : 1e6 , "ntests" : ntests }
446
453
if not baseline .get ('failed' , False ):
447
454
self .error_status |= (8 if return_code > 0 else 16 )
@@ -458,13 +465,13 @@ def report(self, source, timeout, return_code, results, output, pid=None):
458
465
log (" Error in doctesting framework (bad result returned)\n %s\n Tests run before error:" % ("*" * 70 ))
459
466
log (output )
460
467
log ("*" * 70 )
461
- postscript ['lines' ].append (cmd + " # Testing error: bad result" )
468
+ postscript ['lines' ].append (self . report_head ( source , " Testing error: bad result") )
462
469
self .error_status |= 64
463
470
elif result_dict .err == 'noresult' :
464
471
log (" Error in doctesting framework (no result returned)\n %s\n Tests run before error:" % ("*" * 70 ))
465
472
log (output )
466
473
log ("*" * 70 )
467
- postscript ['lines' ].append (cmd + " # Testing error: no result" )
474
+ postscript ['lines' ].append (self . report_head ( source , " Testing error: no result") )
468
475
self .error_status |= 64
469
476
elif result_dict .err == 'tab' :
470
477
if len (result_dict .tab_linenos ) > 5 :
@@ -473,11 +480,11 @@ def report(self, source, timeout, return_code, results, output, pid=None):
473
480
if len (result_dict .tab_linenos ) > 1 :
474
481
tabs = "s" + tabs
475
482
log (" Error: TAB character found at line%s" % (tabs ))
476
- postscript ['lines' ].append (cmd + " # Tab character found" )
483
+ postscript ['lines' ].append (self . report_head ( source , " Tab character found") )
477
484
self .error_status |= 32
478
485
elif result_dict .err == 'line_number' :
479
486
log (" Error: Source line number found" )
480
- postscript ['lines' ].append (cmd + " # Source line number found" )
487
+ postscript ['lines' ].append (self . report_head ( source , " Source line number found") )
481
488
self .error_status |= 256
482
489
elif result_dict .err is not None :
483
490
# This case should not occur
@@ -494,7 +501,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
494
501
if output :
495
502
log ("Tests run before doctest exception:\n " + output )
496
503
log ("*" * 70 )
497
- postscript ['lines' ].append (cmd + " # %s" % fail_msg )
504
+ postscript ['lines' ].append (self . report_head ( source , fail_msg ) )
498
505
if hasattr (result_dict , 'tb' ):
499
506
log (result_dict .tb )
500
507
if hasattr (result_dict , 'walltime' ):
@@ -506,9 +513,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
506
513
f = result_dict .failures
507
514
if f :
508
515
fail_msg = "%s failed" % (count_noun (f , "doctest" ))
509
- if baseline .get ('failed' , False ):
510
- fail_msg += " [failed in baseline]"
511
- postscript ['lines' ].append (cmd + " # %s" % fail_msg )
516
+ postscript ['lines' ].append (self .report_head (source , fail_msg ))
512
517
if not baseline .get ('failed' , False ):
513
518
self .error_status |= 1
514
519
if f or result_dict .err == 'tab' :
0 commit comments