@@ -391,7 +391,7 @@ def __init__(self, config: Config, file: TextIO | None = None) -> None:
391391 self ._progress_nodeids_reported : set [str ] = set ()
392392 self ._timing_nodeids_reported : set [str ] = set ()
393393 self ._show_progress_info = self ._determine_show_progress_info ()
394- self ._collect_report_last_write : float | None = None
394+ self ._collect_report_last_write = timing . Instant ()
395395 self ._already_displayed_warnings : int | None = None
396396 self ._keyboardinterrupt_memo : ExceptionRepr | None = None
397397
@@ -769,7 +769,6 @@ def pytest_collection(self) -> None:
769769 if self .isatty :
770770 if self .config .option .verbose >= 0 :
771771 self .write ("collecting ... " , flush = True , bold = True )
772- self ._collect_report_last_write = timing .perf_counter ()
773772 elif self .config .option .verbose >= 1 :
774773 self .write ("collecting ... " , flush = True , bold = True )
775774
@@ -788,14 +787,13 @@ def report_collect(self, final: bool = False) -> None:
788787 return
789788
790789 if not final :
791- # Only write "collecting" report every 0.5s.
792- t = timing .perf_counter ()
790+ # Only write the "collecting" report every `REPORT_COLLECTING_RESOLUTION`.
793791 if (
794- self ._collect_report_last_write is not None
795- and self . _collect_report_last_write > t - REPORT_COLLECTING_RESOLUTION
792+ self ._collect_report_last_write . elapsed (). seconds
793+ < REPORT_COLLECTING_RESOLUTION
796794 ):
797795 return
798- self ._collect_report_last_write = t
796+ self ._collect_report_last_write = timing . Instant ()
799797
800798 errors = len (self .stats .get ("error" , []))
801799 skipped = len (self .stats .get ("skipped" , []))
@@ -823,7 +821,7 @@ def report_collect(self, final: bool = False) -> None:
823821 @hookimpl (trylast = True )
824822 def pytest_sessionstart (self , session : Session ) -> None :
825823 self ._session = session
826- self ._sessionstarttime = timing .perf_counter ()
824+ self ._session_start = timing .Instant ()
827825 if not self .showheader :
828826 return
829827 self .write_sep ("=" , "test session starts" , bold = True )
@@ -1202,7 +1200,7 @@ def summary_stats(self) -> None:
12021200 if self .verbosity < - 1 :
12031201 return
12041202
1205- session_duration = timing . perf_counter () - self . _sessionstarttime
1203+ session_duration = self . _session_start . elapsed ()
12061204 (parts , main_color ) = self .build_summary_stats_line ()
12071205 line_parts = []
12081206
@@ -1217,7 +1215,7 @@ def summary_stats(self) -> None:
12171215 msg = ", " .join (line_parts )
12181216
12191217 main_markup = {main_color : True }
1220- duration = f" in { format_session_duration (session_duration )} "
1218+ duration = f" in { format_session_duration (session_duration . seconds )} "
12211219 duration_with_markup = self ._tw .markup (duration , ** main_markup )
12221220 if display_sep :
12231221 fullwidth += len (duration_with_markup ) - len (duration )
0 commit comments