From f88c1fe574ea458a0cc9e39bcdde658a2f19d1ab Mon Sep 17 00:00:00 2001 From: piotrhm Date: Thu, 7 May 2020 10:31:02 +0200 Subject: [PATCH 1/3] New flag added. --- src/_pytest/terminal.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 7127ac74bcd..7ceb60c45ce 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -84,6 +84,13 @@ def pytest_addoption(parser): dest="verbose", help="increase verbosity.", ) + group._addoption( + "-d", + action="count", + default=0, + dest="terminal_verbosity", + help="decrease terminal verbosity.", + ) group._addoption( "-q", "--quiet", @@ -309,6 +316,10 @@ def _determine_show_progress_info(self): def verbosity(self): return self.config.option.verbose + @property + def terminal_verbosity(self): + return self.config.option.terminal_verbosity + @property def showheader(self): return self.verbosity >= 0 @@ -433,7 +444,7 @@ def pytest_deselected(self, items): def pytest_runtest_logstart(self, nodeid, location): # ensure that the path is printed before the # 1st test of a module starts running - if self.showlongtestinfo: + if self.showlongtestinfo and self.terminal_verbosity < 1: line = self._locationline(nodeid, *location) self.write_ensure_prefix(line, "") elif self.showfspath: @@ -466,7 +477,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: markup = {"yellow": True} else: markup = {} - if self.verbosity <= 0: + if self.verbosity <= 0 or self.terminal_verbosity > 0: if not running_xdist and self.showfspath: self.write_fspath_result(rep.nodeid, letter, **markup) else: @@ -497,7 +508,7 @@ def _is_last_item(self): def pytest_runtest_logfinish(self, nodeid): assert self._session - if self.verbosity <= 0 and self._show_progress_info: + if (self.verbosity <= 0 or self.terminal_verbosity > 0) and self._show_progress_info: if self._show_progress_info == "count": num_tests = self._session.testscollected progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests))) From 409484da898eb5942e973e89ae4c9b5ce17603d1 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Thu, 7 May 2020 10:39:33 +0200 Subject: [PATCH 2/3] Changelog added. --- AUTHORS | 1 + changelog/6292.feature.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/6292.feature.rst diff --git a/AUTHORS b/AUTHORS index af0dc62c4d8..c58656dcd97 100644 --- a/AUTHORS +++ b/AUTHORS @@ -218,6 +218,7 @@ Pedro Algarvio Philipp Loose Pieter Mulder Piotr Banaszkiewicz +Piotr Helm Pulkit Goyal Punyashloka Biswal Quentin Pradet diff --git a/changelog/6292.feature.rst b/changelog/6292.feature.rst new file mode 100644 index 00000000000..afa9fda6435 --- /dev/null +++ b/changelog/6292.feature.rst @@ -0,0 +1 @@ +New flag -d added which decrease terminal verbosity. Combined with -v/-vv allows to modify how to display test session progress in the terminal. From 598c25298fba200b6d7b9fda0235fbae9154a211 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Thu, 7 May 2020 11:21:35 +0200 Subject: [PATCH 3/3] New flag signature. --- src/_pytest/terminal.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 7ceb60c45ce..7126d9cf228 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -85,7 +85,7 @@ def pytest_addoption(parser): help="increase verbosity.", ) group._addoption( - "-d", + "--dt", action="count", default=0, dest="terminal_verbosity", @@ -508,7 +508,9 @@ def _is_last_item(self): def pytest_runtest_logfinish(self, nodeid): assert self._session - if (self.verbosity <= 0 or self.terminal_verbosity > 0) and self._show_progress_info: + if ( + self.verbosity <= 0 or self.terminal_verbosity > 0 + ) and self._show_progress_info: if self._show_progress_info == "count": num_tests = self._session.testscollected progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests)))