diff --git a/changelog/4225.feature.rst b/changelog/4225.feature.rst new file mode 100644 index 000000000..ffdf0e83f --- /dev/null +++ b/changelog/4225.feature.rst @@ -0,0 +1,3 @@ +Improve performance with collection reporting in non-quiet mode with terminals. + +The "collecting …" message is only printed/updated every 0.5s. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index d207dd785..47d8656d7 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -248,6 +248,7 @@ class TerminalReporter(object): self.isatty = file.isatty() self._progress_nodeids_reported = set() self._show_progress_info = self._determine_show_progress_info() + self._collect_report_last_write = None def _determine_show_progress_info(self): """Return True if we should display progress information based on the current config""" @@ -474,7 +475,11 @@ class TerminalReporter(object): return self._tw.chars_on_current_line def pytest_collection(self): - if not self.isatty and self.config.option.verbose >= 1: + if self.isatty: + if self.config.option.verbose >= 0: + self.write("collecting ... ", bold=True) + self._collect_report_last_write = time.time() + elif self.config.option.verbose >= 1: self.write("collecting ... ", bold=True) def pytest_collectreport(self, report): @@ -485,13 +490,19 @@ class TerminalReporter(object): items = [x for x in report.result if isinstance(x, pytest.Item)] self._numcollected += len(items) if self.isatty: - # self.write_fspath_result(report.nodeid, 'E') self.report_collect() def report_collect(self, final=False): if self.config.option.verbose < 0: return + if not final: + # Only write "collecting" report every 0.5s. + t = time.time() + if self._collect_report_last_write > t - 0.5: + return + self._collect_report_last_write = t + errors = len(self.stats.get("error", [])) skipped = len(self.stats.get("skipped", [])) deselected = len(self.stats.get("deselected", []))