diff --git a/changelog/4741.trivial.rst b/changelog/4741.trivial.rst new file mode 100644 index 000000000..c7903e676 --- /dev/null +++ b/changelog/4741.trivial.rst @@ -0,0 +1,2 @@ +Some verbosity related attributes of the TerminalReporter plugin are now +read only properties. diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index ba0acd269..343d4dd1c 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -435,13 +435,6 @@ class LoggingPlugin(object): # terminal reporter is disabled e.g. by pytest-xdist. return - # FIXME don't set verbosity level and derived attributes of - # terminalwriter directly - terminal_reporter.verbosity = config.option.verbose - terminal_reporter.showheader = terminal_reporter.verbosity >= 0 - terminal_reporter.showfspath = terminal_reporter.verbosity >= 0 - terminal_reporter.showlongtestinfo = terminal_reporter.verbosity > 0 - capture_manager = config.pluginmanager.get_plugin("capturemanager") # if capturemanager plugin is disabled, live logging still works. log_cli_handler = _LiveLoggingStreamHandler(terminal_reporter, capture_manager) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index eb35577f1..33b76ec9c 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -222,12 +222,9 @@ class TerminalReporter(object): import _pytest.config self.config = config - self.verbosity = self.config.option.verbose - self.showheader = self.verbosity >= 0 - self.showfspath = self.verbosity >= 0 - self.showlongtestinfo = self.verbosity > 0 self._numcollected = 0 self._session = None + self._showfspath = None self.stats = {} self.startdir = py.path.local() @@ -255,6 +252,28 @@ class TerminalReporter(object): return False return self.config.getini("console_output_style") in ("progress", "count") + @property + def verbosity(self): + return self.config.option.verbose + + @property + def showheader(self): + return self.verbosity >= 0 + + @property + def showfspath(self): + if self._showfspath is None: + return self.verbosity >= 0 + return self._showfspath + + @showfspath.setter + def showfspath(self, value): + self._showfspath = value + + @property + def showlongtestinfo(self): + return self.verbosity > 0 + def hasopt(self, char): char = {"xfailed": "x", "skipped": "s"}.get(char, char) return char in self.reportchars