Skip to content

Commit e690e19

Browse files
authored
Merge pull request #4225 from blueyed/collect-performance
TerminalWriter: write "collecting" msg only once every 0.5s
2 parents 2a45851 + f8f4c16 commit e690e19

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

changelog/4225.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve performance with collection reporting in non-quiet mode with terminals.
2+
3+
The "collecting …" message is only printed/updated every 0.5s.

src/_pytest/terminal.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def __init__(self, config, file=None):
248248
self.isatty = file.isatty()
249249
self._progress_nodeids_reported = set()
250250
self._show_progress_info = self._determine_show_progress_info()
251+
self._collect_report_last_write = None
251252

252253
def _determine_show_progress_info(self):
253254
"""Return True if we should display progress information based on the current config"""
@@ -474,7 +475,11 @@ def _width_of_current_line(self):
474475
return self._tw.chars_on_current_line
475476

476477
def pytest_collection(self):
477-
if not self.isatty and self.config.option.verbose >= 1:
478+
if self.isatty:
479+
if self.config.option.verbose >= 0:
480+
self.write("collecting ... ", bold=True)
481+
self._collect_report_last_write = time.time()
482+
elif self.config.option.verbose >= 1:
478483
self.write("collecting ... ", bold=True)
479484

480485
def pytest_collectreport(self, report):
@@ -485,13 +490,19 @@ def pytest_collectreport(self, report):
485490
items = [x for x in report.result if isinstance(x, pytest.Item)]
486491
self._numcollected += len(items)
487492
if self.isatty:
488-
# self.write_fspath_result(report.nodeid, 'E')
489493
self.report_collect()
490494

491495
def report_collect(self, final=False):
492496
if self.config.option.verbose < 0:
493497
return
494498

499+
if not final:
500+
# Only write "collecting" report every 0.5s.
501+
t = time.time()
502+
if self._collect_report_last_write > t - 0.5:
503+
return
504+
self._collect_report_last_write = t
505+
495506
errors = len(self.stats.get("error", []))
496507
skipped = len(self.stats.get("skipped", []))
497508
deselected = len(self.stats.get("deselected", []))

0 commit comments

Comments
 (0)