Skip to content

Commit 719f8d0

Browse files
author
Matthias Koeppe
committed
DocTestReporter.report_head: Move all printing of 'failed in baseline' here
1 parent 235824b commit 719f8d0

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/sage/doctest/forker.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,6 @@ def serial_dispatch(self):
17251725
for source in self.controller.sources:
17261726
heading = self.controller.reporter.report_head(source)
17271727
baseline = self.controller.source_baseline(source)
1728-
if baseline.get('failed', False):
1729-
heading += " # [failed in baseline]"
17301728
if not self.controller.options.only_errors:
17311729
self.controller.log(heading)
17321730

@@ -1997,8 +1995,6 @@ def sel_exit():
19971995
worker_options.target_walltime = (target_endtime - now) / (max(1, pending_tests / opt.nthreads))
19981996
w = DocTestWorker(source, options=worker_options, funclist=[sel_exit], baseline=baseline)
19991997
heading = self.controller.reporter.report_head(w.source)
2000-
if baseline.get('failed', False):
2001-
heading += " # [failed in baseline]"
20021998
if not self.controller.options.only_errors:
20031999
w.messages = heading + "\n"
20042000
# Store length of heading to detect if the

src/sage/doctest/reporting.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ def were_doctests_with_optional_tag_run(self, tag):
162162
return True
163163
return False
164164

165-
def report_head(self, source):
165+
def report_head(self, source, fail_msg=None):
166166
"""
167-
Return the "sage -t [options] file.py" line as string.
167+
Return the ``sage -t [options] file.py`` line as string.
168168
169169
INPUT:
170170
171171
- ``source`` -- a source from :mod:`sage.doctest.sources`
172172
173+
- ``fail_msg`` -- ``None`` or a string
174+
173175
EXAMPLES::
174176
175177
sage: from sage.doctest.reporting import DocTestReporter
@@ -190,6 +192,8 @@ def report_head(self, source):
190192
sage: DD.long = True
191193
sage: print(DTR.report_head(FDS))
192194
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
193197
"""
194198
cmd = "sage -t"
195199
if self.controller.options.long:
@@ -206,6 +210,13 @@ def report_head(self, source):
206210
if environment != "sage.repl.ipython_kernel.all_jupyter":
207211
cmd += f" --environment={environment}"
208212
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]"
209220
return cmd
210221

211222
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):
420431
fail_msg += " (and interrupt failed)"
421432
else:
422433
fail_msg += " (with %s after interrupt)" % signal_name(sig)
423-
if baseline.get('failed', False):
424-
fail_msg += " [failed in baseline]"
425434
log(" %s\n%s\nTests run before %s timed out:" % (fail_msg, "*"*70, process_name))
426435
log(output)
427436
log("*"*70)
428-
postscript['lines'].append(cmd + " # %s" % fail_msg)
437+
postscript['lines'].append(self.report_head(source, fail_msg))
429438
stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests}
430439
if not baseline.get('failed', False):
431440
self.error_status |= 4
@@ -436,12 +445,10 @@ def report(self, source, timeout, return_code, results, output, pid=None):
436445
fail_msg = "Killed due to %s" % signal_name(-return_code)
437446
if ntests > 0:
438447
fail_msg += " after testing finished"
439-
if baseline.get('failed', False):
440-
fail_msg += " [failed in baseline]"
441448
log(" %s\n%s\nTests run before %s failed:" % (fail_msg,"*"*70, process_name))
442449
log(output)
443450
log("*"*70)
444-
postscript['lines'].append(cmd + " # %s" % fail_msg)
451+
postscript['lines'].append(self.report_head(source, fail_msg))
445452
stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests}
446453
if not baseline.get('failed', False):
447454
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):
458465
log(" Error in doctesting framework (bad result returned)\n%s\nTests run before error:" % ("*"*70))
459466
log(output)
460467
log("*"*70)
461-
postscript['lines'].append(cmd + " # Testing error: bad result")
468+
postscript['lines'].append(self.report_head(source, "Testing error: bad result"))
462469
self.error_status |= 64
463470
elif result_dict.err == 'noresult':
464471
log(" Error in doctesting framework (no result returned)\n%s\nTests run before error:" % ("*"*70))
465472
log(output)
466473
log("*"*70)
467-
postscript['lines'].append(cmd + " # Testing error: no result")
474+
postscript['lines'].append(self.report_head(source, "Testing error: no result"))
468475
self.error_status |= 64
469476
elif result_dict.err == 'tab':
470477
if len(result_dict.tab_linenos) > 5:
@@ -473,11 +480,11 @@ def report(self, source, timeout, return_code, results, output, pid=None):
473480
if len(result_dict.tab_linenos) > 1:
474481
tabs = "s" + tabs
475482
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"))
477484
self.error_status |= 32
478485
elif result_dict.err == 'line_number':
479486
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"))
481488
self.error_status |= 256
482489
elif result_dict.err is not None:
483490
# This case should not occur
@@ -494,7 +501,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
494501
if output:
495502
log("Tests run before doctest exception:\n" + output)
496503
log("*"*70)
497-
postscript['lines'].append(cmd + " # %s" % fail_msg)
504+
postscript['lines'].append(self.report_head(source, fail_msg))
498505
if hasattr(result_dict, 'tb'):
499506
log(result_dict.tb)
500507
if hasattr(result_dict, 'walltime'):
@@ -506,9 +513,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
506513
f = result_dict.failures
507514
if f:
508515
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))
512517
if not baseline.get('failed', False):
513518
self.error_status |= 1
514519
if f or result_dict.err == 'tab':

0 commit comments

Comments
 (0)