@@ -157,7 +157,7 @@ def __init__(self, outcome, report, logfile, config):
157
157
if getattr (report , "when" , "call" ) != "call" :
158
158
self .test_id = "::" .join ([report .nodeid , report .when ])
159
159
self .time = getattr (report , "duration" , 0.0 )
160
- self .formatted_time = getattr (report , "formatted_duration" , 0.0 )
160
+ self .formatted_time = self . _format_time (report )
161
161
self .outcome = outcome
162
162
self .additional_html = []
163
163
self .links_html = []
@@ -283,6 +283,37 @@ def append_extra_html(self, extra, extra_index, test_index):
283
283
)
284
284
self .links_html .append (" " )
285
285
286
+ def _format_time (self , report ):
287
+ # parse the report duration into its display version and return
288
+ # it to the caller
289
+ duration = getattr (report , "duration" , None )
290
+ if duration is None :
291
+ return ""
292
+
293
+ duration_formatter = getattr (report , "duration_formatter" , None )
294
+ string_duration = str (duration )
295
+ if duration_formatter is None :
296
+ if "." in string_duration :
297
+ split_duration = string_duration .split ("." )
298
+ split_duration [1 ] = split_duration [1 ][0 :2 ]
299
+
300
+ string_duration = "." .join (split_duration )
301
+
302
+ return string_duration
303
+ else :
304
+ # support %f, since time.strftime doesn't support it out of the box
305
+ # keep a precision of 2 for legacy reasons
306
+ formatted_milliseconds = "00"
307
+ if "." in string_duration :
308
+ milliseconds = string_duration .split ("." )[1 ]
309
+ formatted_milliseconds = milliseconds [0 :2 ]
310
+
311
+ duration_formatter = duration_formatter .replace (
312
+ "%f" , formatted_milliseconds
313
+ )
314
+ duration_as_gmtime = time .gmtime (report .duration )
315
+ return time .strftime (duration_formatter , duration_as_gmtime )
316
+
286
317
def _populate_html_log_div (self , log , report ):
287
318
if report .longrepr :
288
319
# longreprtext is only filled out on failure by pytest
@@ -425,6 +456,10 @@ def append_failed(self, report):
425
456
self .errors += 1
426
457
self ._appendrow ("Error" , report )
427
458
459
+ def append_rerun (self , report ):
460
+ self .rerun += 1
461
+ self ._appendrow ("Rerun" , report )
462
+
428
463
def append_skipped (self , report ):
429
464
if hasattr (report , "wasxfail" ):
430
465
self .xfailed += 1
@@ -433,11 +468,6 @@ def append_skipped(self, report):
433
468
self .skipped += 1
434
469
self ._appendrow ("Skipped" , report )
435
470
436
- def append_other (self , report ):
437
- # For now, the only "other" the plugin give support is rerun
438
- self .rerun += 1
439
- self ._appendrow ("Rerun" , report )
440
-
441
471
def _generate_report (self , session ):
442
472
suite_stop_time = time .time ()
443
473
suite_time_delta = suite_stop_time - self .suite_start_time
@@ -604,32 +634,6 @@ def generate_summary_item(self):
604
634
unicode_doc = unicode_doc .encode ("utf-8" , errors = "xmlcharrefreplace" )
605
635
return unicode_doc .decode ("utf-8" )
606
636
607
- def _format_duration (self , report ):
608
- # parse the report duration into its display version and return it to the caller
609
- duration_formatter = getattr (report , "duration_formatter" , None )
610
- string_duration = str (report .duration )
611
- if duration_formatter is None :
612
- if "." in string_duration :
613
- split_duration = string_duration .split ("." )
614
- split_duration [1 ] = split_duration [1 ][0 :2 ]
615
-
616
- string_duration = "." .join (split_duration )
617
-
618
- return string_duration
619
- else :
620
- # support %f, since time.strftime doesn't support it out of the box
621
- # keep a precision of 2 for legacy reasons
622
- formatted_milliseconds = "00"
623
- if "." in string_duration :
624
- milliseconds = string_duration .split ("." )[1 ]
625
- formatted_milliseconds = milliseconds [0 :2 ]
626
-
627
- duration_formatter = duration_formatter .replace (
628
- "%f" , formatted_milliseconds
629
- )
630
- duration_as_gmtime = time .gmtime (report .duration )
631
- return time .strftime (duration_formatter , duration_as_gmtime )
632
-
633
637
def _generate_environment (self , config ):
634
638
if not hasattr (config , "_metadata" ) or config ._metadata is None :
635
639
return []
@@ -685,22 +689,23 @@ def _post_process_reports(self):
685
689
# through them all to figure out the outcome, xfail, duration,
686
690
# extras, and when it swapped from pass
687
691
for test_report in test_reports :
688
- full_text += test_report .longreprtext
689
- extras .extend (getattr (test_report , "extra" , []))
690
- duration += getattr (test_report , "duration" , 0.0 )
692
+ if test_report .outcome == "rerun" :
693
+ # reruns are separate test runs for all intensive purposes
694
+ self .append_rerun (test_report )
695
+ else :
696
+ full_text += test_report .longreprtext
697
+ extras .extend (getattr (test_report , "extra" , []))
698
+ duration += getattr (test_report , "duration" , 0.0 )
691
699
692
- if (
693
- test_report .outcome not in ("passed" , "rerun" )
694
- and outcome == "passed"
695
- ):
696
- outcome = test_report .outcome
697
- failure_when = test_report .when
700
+ if (
701
+ test_report .outcome not in ("passed" , "rerun" )
702
+ and outcome == "passed"
703
+ ):
704
+ outcome = test_report .outcome
705
+ failure_when = test_report .when
698
706
699
- if hasattr (test_report , "wasxfail" ):
700
- wasxfail = True
701
-
702
- if test_report .outcome == "rerun" :
703
- self .append_other (test_report )
707
+ if hasattr (test_report , "wasxfail" ):
708
+ wasxfail = True
704
709
705
710
# the following test_report.<X> = settings come at the end of us
706
711
# looping through all test_reports that make up a single
@@ -715,7 +720,6 @@ def _post_process_reports(self):
715
720
test_report .longrepr = full_text
716
721
test_report .extra = extras
717
722
test_report .duration = duration
718
- test_report .formatted_duration = self ._format_duration (test_report )
719
723
720
724
if wasxfail :
721
725
test_report .wasxfail = True
@@ -728,9 +732,6 @@ def _post_process_reports(self):
728
732
test_report .when = failure_when
729
733
self .append_failed (test_report )
730
734
731
- # we don't append other here since the only case supported
732
- # for append_other is rerun, which is handled in the loop above
733
-
734
735
def pytest_runtest_logreport (self , report ):
735
736
self .reports [report .nodeid ].append (report )
736
737
0 commit comments