Skip to content

Commit

Permalink
terminal: fix progress percentages not aligning correctly in xdist
Browse files Browse the repository at this point in the history
Fix #7166
  • Loading branch information
bluetech committed Apr 28, 2024
1 parent 1a84d23 commit 50d1e81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/7166.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed progress percentages (the ``[ 87%]`` at the edge of the screen) sometimes not aligning correctly when running with pytest-xdist ``-n``.
24 changes: 17 additions & 7 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,18 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
markup = {"yellow": True}
else:
markup = {}
self._progress_nodeids_reported.add(rep.nodeid)
if self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0:
self._tw.write(letter, **markup)
# When running in xdist, the logreport and logfinish of multiple
# items are interspersed, e.g. `logreport`, `logreport`,
# `logfinish`, `logfinish`. To avoid the "past edge" calculation
# from getting confused and overflowing (#7166), do the past edge
# printing here and not in logfinish, except for the 100% which
# should only be printed after all teardowns are finished.
if self._show_progress_info and not self._is_last_item:
self._write_progress_information_if_past_edge()
else:
self._progress_nodeids_reported.add(rep.nodeid)
line = self._locationline(rep.nodeid, *rep.location)
running_xdist = hasattr(rep, "node")

Check warning on line 620 in src/_pytest/terminal.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/terminal.py#L620

Added line #L620 was not covered by tests
if not running_xdist:
Expand Down Expand Up @@ -649,17 +657,19 @@ def _is_last_item(self) -> bool:
assert self._session is not None
return len(self._progress_nodeids_reported) == self._session.testscollected

def pytest_runtest_logfinish(self, nodeid: str) -> None:
@hookimpl(wrapper=True)
def pytest_runtestloop(self) -> Generator[None, object, object]:
result = yield

# Write the final/100% progress -- deferred until the loop is complete.
if (
self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0
and self._show_progress_info
and self._progress_nodeids_reported
):
self._progress_nodeids_reported.add(nodeid)
self._write_progress_information_filling_space()

if self._is_last_item:
self._write_progress_information_filling_space()
else:
self._write_progress_information_if_past_edge()
return result

def _get_progress_information_message(self) -> str:
assert self._session
Expand Down

0 comments on commit 50d1e81

Please sign in to comment.