Skip to content

Commit 50d1e81

Browse files
committed
terminal: fix progress percentages not aligning correctly in xdist
Fix #7166
1 parent 1a84d23 commit 50d1e81

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

changelog/7166.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed progress percentages (the ``[ 87%]`` at the edge of the screen) sometimes not aligning correctly when running with pytest-xdist ``-n``.

src/_pytest/terminal.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)