66import math
77import os
88import re
9+ import time
910import warnings
1011from collections import defaultdict
1112from html import escape
@@ -33,6 +34,7 @@ def __init__(self, report_path, config, report_data, template, css):
3334 self ._reports = defaultdict (dict )
3435 self ._report = report_data
3536 self ._report .title = self ._report_path .name
37+ self ._suite_start_time = time .time ()
3638
3739 @property
3840 def css (self ):
@@ -173,7 +175,8 @@ def pytest_sessionstart(self, session):
173175 self ._report .table_header = _fix_py (headers )
174176
175177 self ._report .running_state = "started"
176- self ._generate_report ()
178+ if self ._config .getini ("generate_report_on_test" ):
179+ self ._generate_report ()
177180
178181 @pytest .hookimpl (trylast = True )
179182 def pytest_sessionfinish (self , session ):
@@ -184,6 +187,8 @@ def pytest_sessionfinish(self, session):
184187 session = session ,
185188 )
186189 self ._report .running_state = "finished"
190+ suite_stop_time = time .time ()
191+ self ._report .total_duration = suite_stop_time - self ._suite_start_time
187192 self ._generate_report ()
188193
189194 @pytest .hookimpl (trylast = True )
@@ -223,8 +228,6 @@ def pytest_runtest_logreport(self, report):
223228 else :
224229 self ._reports [report .nodeid ][key ] = [report ]
225230
226- self ._report .total_duration += report .duration
227-
228231 finished = report .when == "teardown" and report .outcome != "rerun"
229232 if not finished :
230233 return
0 commit comments