Skip to content

Commit c71920c

Browse files
committed
terminal: add TerminalReporter.reported_progress
Return how many items have been reported in the progress so far. This cleans up the code a bit, but also allows grabbing this info without accessing the internals. We can consider making this property public separately.
1 parent 5a73c57 commit c71920c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/_pytest/terminal.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ def showfspath(self, value: bool | None) -> None:
454454
def showlongtestinfo(self) -> bool:
455455
return self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) > 0
456456

457+
@property
458+
def reported_progress(self) -> int:
459+
"""The amount of items reported in the progress so far.
460+
461+
:meta private:
462+
"""
463+
return len(self._progress_nodeids_reported)
464+
457465
def hasopt(self, char: str) -> bool:
458466
char = {"xfailed": "x", "skipped": "s"}.get(char, char)
459467
return char in self.reportchars
@@ -684,7 +692,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
684692
@property
685693
def _is_last_item(self) -> bool:
686694
assert self._session is not None
687-
return len(self._progress_nodeids_reported) == self._session.testscollected
695+
return self.reported_progress == self._session.testscollected
688696

689697
@hookimpl(wrapper=True)
690698
def pytest_runtestloop(self) -> Generator[None, object, object]:
@@ -694,7 +702,7 @@ def pytest_runtestloop(self) -> Generator[None, object, object]:
694702
if (
695703
self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0
696704
and self._show_progress_info
697-
and self._progress_nodeids_reported
705+
and self.reported_progress
698706
):
699707
self._write_progress_information_filling_space()
700708

@@ -705,7 +713,7 @@ def _get_progress_information_message(self) -> str:
705713
collected = self._session.testscollected
706714
if self._show_progress_info == "count":
707715
if collected:
708-
progress = len(self._progress_nodeids_reported)
716+
progress = self.reported_progress
709717
counter_format = f"{{:{len(str(collected))}d}}"
710718
format_string = f" [{counter_format}/{{}}]"
711719
return format_string.format(progress, collected)
@@ -742,7 +750,7 @@ def _get_progress_information_message(self) -> str:
742750
)
743751
return ""
744752
if collected:
745-
return f" [{len(self._progress_nodeids_reported) * 100 // collected:3d}%]"
753+
return f" [{self.reported_progress * 100 // collected:3d}%]"
746754
return " [100%]"
747755

748756
def _write_progress_information_if_past_edge(self) -> None:

0 commit comments

Comments
 (0)