Skip to content

Commit

Permalink
TerminalWriter: write "collecting" msg only once every 0.1s
Browse files Browse the repository at this point in the history
Running `pytest -k doesnotmatch` on pytest's own tests takes ~3s with
Kitty terminal for me, but only ~1s with `-q`.
It also is faster with urxvt, but still takes 2.2s there.

This patch only calls `report_collect` every 0.1s, which is good enough
for reporting collection progress, and improves the time with both Kitty
and urxvt to ~1.2s for me.
  • Loading branch information
blueyed committed Oct 24, 2018
1 parent 2a45851 commit cfaaf42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions 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.
14 changes: 12 additions & 2 deletions src/_pytest/terminal.py
Expand Up @@ -248,6 +248,7 @@ def __init__(self, config, file=None):
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"""
Expand Down Expand Up @@ -474,7 +475,11 @@ def _width_of_current_line(self):
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):
Expand All @@ -485,7 +490,12 @@ def pytest_collectreport(self, report):
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')
# 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

self.report_collect()

def report_collect(self, final=False):
Expand Down

0 comments on commit cfaaf42

Please sign in to comment.