@@ -1235,7 +1235,7 @@ def compile_and_execute(self, example, compiler, globs):
1235
1235
example .total_state = self .running_global_digest .hexdigest ()
1236
1236
example .doctest_state = self .running_doctest_digest .hexdigest ()
1237
1237
1238
- def _failure_header (self , test , example , message = 'Failed example:' ):
1238
+ def _failure_header (self , test , example , message = 'Failed example:' , extra = None ):
1239
1239
"""
1240
1240
We strip out ``sage:`` prompts, so we override
1241
1241
:meth:`doctest.DocTestRunner._failure_header` for better
@@ -1247,6 +1247,14 @@ def _failure_header(self, test, example, message='Failed example:'):
1247
1247
1248
1248
- ``example`` -- a :class:`doctest.Example` instance in ``test``
1249
1249
1250
+ - ``message`` -- a message to be shown. Must not have a newline
1251
+
1252
+ - ``extra`` -- an extra message to be shown in GitHub annotation
1253
+
1254
+ Note that ``message`` and ``extra`` are not accepted by
1255
+ :meth:`doctest.DocTestRunner._failure_header`, as such by Liskov
1256
+ substitution principle this method must be callable without passing those.
1257
+
1250
1258
OUTPUT: string used for reporting that the given example failed
1251
1259
1252
1260
EXAMPLES::
@@ -1310,6 +1318,8 @@ def _failure_header(self, test, example, message='Failed example:'):
1310
1318
message += ' [failed in baseline]'
1311
1319
else :
1312
1320
command = f'::error title={ message } '
1321
+ if extra :
1322
+ message += f': { extra } '
1313
1323
if extra := getattr (example , 'extra' , None ):
1314
1324
message += f': { extra } '
1315
1325
if test .filename :
@@ -1610,12 +1620,12 @@ def report_overtime(self, out, test, example, got, *, check_timer=None):
1610
1620
Test ran for 1.23s cpu, 2.50s wall
1611
1621
Check ran for 2.34s cpu, 3.12s wall
1612
1622
"""
1613
- out ( self . _failure_header ( test , example , 'Warning: slow doctest:' ) +
1614
- ( 'Test ran for %.2fs cpu, %.2fs wall \n Check ran for %.2fs cpu, %.2fs wall \n '
1615
- % ( example .cputime ,
1616
- example . walltime ,
1617
- check_timer .cputime ,
1618
- check_timer . walltime )) )
1623
+ time_info = ( 'Test ran for %.2fs cpu, %.2fs wall \n Check ran for %.2fs cpu, %.2fs wall \n '
1624
+ % ( example . cputime ,
1625
+ example .walltime ,
1626
+ check_timer . cputime ,
1627
+ check_timer .walltime ))
1628
+ out ( self . _failure_header ( test , example , 'Warning: slow doctest:' , time_info ) + time_info )
1619
1629
1620
1630
def report_unexpected_exception (self , out , test , example , exc_info ):
1621
1631
r"""
0 commit comments