@@ -604,10 +604,18 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
604604 markup = {"yellow" : True }
605605 else :
606606 markup = {}
607+ self ._progress_nodeids_reported .add (rep .nodeid )
607608 if self .config .get_verbosity (Config .VERBOSITY_TEST_CASES ) <= 0 :
608609 self ._tw .write (letter , ** markup )
610+ # When running in xdist, the logreport and logfinish of multiple
611+ # items are interspersed, e.g. `logreport`, `logreport`,
612+ # `logfinish`, `logfinish`. To avoid the "past edge" calculation
613+ # from getting confused and overflowing (#7166), do the past edge
614+ # printing here and not in logfinish, except for the 100% which
615+ # should only be printed after all teardowns are finished.
616+ if self ._show_progress_info and not self ._is_last_item :
617+ self ._write_progress_information_if_past_edge ()
609618 else :
610- self ._progress_nodeids_reported .add (rep .nodeid )
611619 line = self ._locationline (rep .nodeid , * rep .location )
612620 running_xdist = hasattr (rep , "node" )
613621 if not running_xdist :
@@ -649,17 +657,19 @@ def _is_last_item(self) -> bool:
649657 assert self ._session is not None
650658 return len (self ._progress_nodeids_reported ) == self ._session .testscollected
651659
652- def pytest_runtest_logfinish (self , nodeid : str ) -> None :
660+ @hookimpl (wrapper = True )
661+ def pytest_runtestloop (self ) -> Generator [None , object , object ]:
662+ result = yield
663+
664+ # Write the final/100% progress -- deferred until the loop is complete.
653665 if (
654666 self .config .get_verbosity (Config .VERBOSITY_TEST_CASES ) <= 0
655667 and self ._show_progress_info
668+ and self ._progress_nodeids_reported
656669 ):
657- self ._progress_nodeids_reported . add ( nodeid )
670+ self ._write_progress_information_filling_space ( )
658671
659- if self ._is_last_item :
660- self ._write_progress_information_filling_space ()
661- else :
662- self ._write_progress_information_if_past_edge ()
672+ return result
663673
664674 def _get_progress_information_message (self ) -> str :
665675 assert self ._session
0 commit comments