Skip to content

Commit 3a5c08a

Browse files
committed
terminal: fix progress percentages not aligning correctly in xdist
Fix #7166
1 parent 174561b commit 3a5c08a

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
@@ -603,10 +603,18 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
603603
markup = {"yellow": True}
604604
else:
605605
markup = {}
606+
self._progress_nodeids_reported.add(rep.nodeid)
606607
if self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0:
607608
self._tw.write(letter, **markup)
609+
# When running in xdist, the logreport and logfinish of multiple
610+
# items are interspersed, e.g. `logreport`, `logreport`,
611+
# `logfinish`, `logfinish`. To avoid the "past edge" calculation
612+
# from getting confused and overflowing (#7166), do the past edge
613+
# printing here and not in logfinish, except for the 100% which
614+
# should only be printed after all teardowns are finished.
615+
if self._show_progress_info and not self._is_last_item:
616+
self._write_progress_information_if_past_edge()
608617
else:
609-
self._progress_nodeids_reported.add(rep.nodeid)
610618
line = self._locationline(rep.nodeid, *rep.location)
611619
running_xdist = hasattr(rep, "node")
612620
if not running_xdist:
@@ -648,17 +656,19 @@ def _is_last_item(self) -> bool:
648656
assert self._session is not None
649657
return len(self._progress_nodeids_reported) == self._session.testscollected
650658

651-
def pytest_runtest_logfinish(self, nodeid: str) -> None:
659+
@hookimpl(wrapper=True)
660+
def pytest_runtestloop(self) -> Generator[None, object, object]:
661+
result = yield
662+
663+
# Write the final/100% progress -- deferred until the loop is complete.
652664
if (
653665
self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0
654666
and self._show_progress_info
667+
and self._progress_nodeids_reported
655668
):
656-
self._progress_nodeids_reported.add(nodeid)
669+
self._write_progress_information_filling_space()
657670

658-
if self._is_last_item:
659-
self._write_progress_information_filling_space()
660-
else:
661-
self._write_progress_information_if_past_edge()
671+
return result
662672

663673
def _get_progress_information_message(self) -> str:
664674
assert self._session

0 commit comments

Comments
 (0)