@@ -166,7 +166,7 @@ def __init__(self, outcome, report, logfile, config):
166166 if getattr (report , "when" , "call" ) != "call" :
167167 self .test_id = "::" .join ([report .nodeid , report .when ])
168168 self .time = getattr (report , "duration" , 0.0 )
169- self .formatted_time = getattr (report , "formatted_duration" , 0.0 )
169+ self .formatted_time = self . _format_time (report )
170170 self .outcome = outcome
171171 self .additional_html = []
172172 self .links_html = []
@@ -292,6 +292,37 @@ def append_extra_html(self, extra, extra_index, test_index):
292292 )
293293 self .links_html .append (" " )
294294
295+ def _format_time (self , report ):
296+ # parse the report duration into its display version and return
297+ # it to the caller
298+ duration = getattr (report , "duration" , None )
299+ if duration is None :
300+ return ""
301+
302+ duration_formatter = getattr (report , "duration_formatter" , None )
303+ string_duration = str (duration )
304+ if duration_formatter is None :
305+ if "." in string_duration :
306+ split_duration = string_duration .split ("." )
307+ split_duration [1 ] = split_duration [1 ][0 :2 ]
308+
309+ string_duration = "." .join (split_duration )
310+
311+ return string_duration
312+ else :
313+ # support %f, since time.strftime doesn't support it out of the box
314+ # keep a precision of 2 for legacy reasons
315+ formatted_milliseconds = "00"
316+ if "." in string_duration :
317+ milliseconds = string_duration .split ("." )[1 ]
318+ formatted_milliseconds = milliseconds [0 :2 ]
319+
320+ duration_formatter = duration_formatter .replace (
321+ "%f" , formatted_milliseconds
322+ )
323+ duration_as_gmtime = time .gmtime (report .duration )
324+ return time .strftime (duration_formatter , duration_as_gmtime )
325+
295326 def _populate_html_log_div (self , log , report ):
296327 if report .longrepr :
297328 # longreprtext is only filled out on failure by pytest
@@ -434,6 +465,10 @@ def append_failed(self, report):
434465 self .errors += 1
435466 self ._appendrow ("Error" , report )
436467
468+ def append_rerun (self , report ):
469+ self .rerun += 1
470+ self ._appendrow ("Rerun" , report )
471+
437472 def append_skipped (self , report ):
438473 if hasattr (report , "wasxfail" ):
439474 self .xfailed += 1
@@ -442,11 +477,6 @@ def append_skipped(self, report):
442477 self .skipped += 1
443478 self ._appendrow ("Skipped" , report )
444479
445- def append_other (self , report ):
446- # For now, the only "other" the plugin give support is rerun
447- self .rerun += 1
448- self ._appendrow ("Rerun" , report )
449-
450480 def _generate_report (self , session ):
451481 suite_stop_time = time .time ()
452482 suite_time_delta = suite_stop_time - self .suite_start_time
@@ -613,32 +643,6 @@ def generate_summary_item(self):
613643 unicode_doc = unicode_doc .encode ("utf-8" , errors = "xmlcharrefreplace" )
614644 return unicode_doc .decode ("utf-8" )
615645
616- def _format_duration (self , report ):
617- # parse the report duration into its display version and return it to the caller
618- duration_formatter = getattr (report , "duration_formatter" , None )
619- string_duration = str (report .duration )
620- if duration_formatter is None :
621- if "." in string_duration :
622- split_duration = string_duration .split ("." )
623- split_duration [1 ] = split_duration [1 ][0 :2 ]
624-
625- string_duration = "." .join (split_duration )
626-
627- return string_duration
628- else :
629- # support %f, since time.strftime doesn't support it out of the box
630- # keep a precision of 2 for legacy reasons
631- formatted_milliseconds = "00"
632- if "." in string_duration :
633- milliseconds = string_duration .split ("." )[1 ]
634- formatted_milliseconds = milliseconds [0 :2 ]
635-
636- duration_formatter = duration_formatter .replace (
637- "%f" , formatted_milliseconds
638- )
639- duration_as_gmtime = time .gmtime (report .duration )
640- return time .strftime (duration_formatter , duration_as_gmtime )
641-
642646 def _generate_environment (self , config ):
643647 if not hasattr (config , "_metadata" ) or config ._metadata is None :
644648 return []
@@ -694,22 +698,23 @@ def _post_process_reports(self):
694698 # through them all to figure out the outcome, xfail, duration,
695699 # extras, and when it swapped from pass
696700 for test_report in test_reports :
697- full_text += test_report .longreprtext
698- extras .extend (getattr (test_report , "extra" , []))
699- duration += getattr (test_report , "duration" , 0.0 )
701+ if test_report .outcome == "rerun" :
702+ # reruns are separate test runs for all intensive purposes
703+ self .append_rerun (test_report )
704+ else :
705+ full_text += test_report .longreprtext
706+ extras .extend (getattr (test_report , "extra" , []))
707+ duration += getattr (test_report , "duration" , 0.0 )
700708
701- if (
702- test_report .outcome not in ("passed" , "rerun" )
703- and outcome == "passed"
704- ):
705- outcome = test_report .outcome
706- failure_when = test_report .when
709+ if (
710+ test_report .outcome not in ("passed" , "rerun" )
711+ and outcome == "passed"
712+ ):
713+ outcome = test_report .outcome
714+ failure_when = test_report .when
707715
708- if hasattr (test_report , "wasxfail" ):
709- wasxfail = True
710-
711- if test_report .outcome == "rerun" :
712- self .append_other (test_report )
716+ if hasattr (test_report , "wasxfail" ):
717+ wasxfail = True
713718
714719 # the following test_report.<X> = settings come at the end of us
715720 # looping through all test_reports that make up a single
@@ -724,7 +729,6 @@ def _post_process_reports(self):
724729 test_report .longrepr = full_text
725730 test_report .extra = extras
726731 test_report .duration = duration
727- test_report .formatted_duration = self ._format_duration (test_report )
728732
729733 if wasxfail :
730734 test_report .wasxfail = True
@@ -737,9 +741,6 @@ def _post_process_reports(self):
737741 test_report .when = failure_when
738742 self .append_failed (test_report )
739743
740- # we don't append other here since the only case supported
741- # for append_other is rerun, which is handled in the loop above
742-
743744 def pytest_runtest_logreport (self , report ):
744745 self .reports [report .nodeid ].append (report )
745746
0 commit comments