From 0b70300ba4c00f2fdab1415b33ac6b035418e648 Mon Sep 17 00:00:00 2001 From: piotrhm Date: Mon, 25 May 2020 14:18:57 +0200 Subject: [PATCH] Added requested modifications --- AUTHORS | 1 + changelog/6471.feature.rst | 1 + src/_pytest/terminal.py | 63 ++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 changelog/6471.feature.rst diff --git a/AUTHORS b/AUTHORS index fdcd5b6e0..821a7d8f4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -227,6 +227,7 @@ Pedro Algarvio Philipp Loose Pieter Mulder Piotr Banaszkiewicz +Piotr Helm Prashant Anand Pulkit Goyal Punyashloka Biswal diff --git a/changelog/6471.feature.rst b/changelog/6471.feature.rst new file mode 100644 index 000000000..bc2d7564e --- /dev/null +++ b/changelog/6471.feature.rst @@ -0,0 +1 @@ +New flags --no-header and --no-summary added. The first one disables header, the second one disables summary. \ No newline at end of file diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 9c2665fb8..2a98e4ceb 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -115,6 +115,20 @@ def pytest_addoption(parser: Parser) -> None: dest="verbose", help="increase verbosity.", ) + group._addoption( + "--no-header", + action="count", + default=0, + dest="no_header", + help="disable header", + ) + group._addoption( + "--no-summary", + action="count", + default=0, + dest="no_summary", + help="disable summary", + ) group._addoption( "-q", "--quiet", @@ -351,6 +365,14 @@ class TerminalReporter: def showheader(self) -> bool: return self.verbosity >= 0 + @property + def no_header(self) -> bool: + return self.config.option.no_header + + @property + def no_summary(self) -> bool: + return self.config.option.no_summary + @property def showfspath(self) -> bool: if self._showfspath is None: @@ -660,25 +682,26 @@ class TerminalReporter: return self.write_sep("=", "test session starts", bold=True) verinfo = platform.python_version() - msg = "platform {} -- Python {}".format(sys.platform, verinfo) - pypy_version_info = getattr(sys, "pypy_version_info", None) - if pypy_version_info: - verinfo = ".".join(map(str, pypy_version_info[:3])) - msg += "[pypy-{}-{}]".format(verinfo, pypy_version_info[3]) - msg += ", pytest-{}, py-{}, pluggy-{}".format( - pytest.__version__, py.__version__, pluggy.__version__ - ) - if ( - self.verbosity > 0 - or self.config.option.debug - or getattr(self.config.option, "pastebin", None) - ): - msg += " -- " + str(sys.executable) - self.write_line(msg) - lines = self.config.hook.pytest_report_header( - config=self.config, startdir=self.startdir - ) - self._write_report_lines_from_hooks(lines) + if self.no_header == 0: + msg = "platform {} -- Python {}".format(sys.platform, verinfo) + pypy_version_info = getattr(sys, "pypy_version_info", None) + if pypy_version_info: + verinfo = ".".join(map(str, pypy_version_info[:3])) + msg += "[pypy-{}-{}]".format(verinfo, pypy_version_info[3]) + msg += ", pytest-{}, py-{}, pluggy-{}".format( + pytest.__version__, py.__version__, pluggy.__version__ + ) + if ( + self.verbosity > 0 + or self.config.option.debug + or getattr(self.config.option, "pastebin", None) + ): + msg += " -- " + str(sys.executable) + self.write_line(msg) + lines = self.config.hook.pytest_report_header( + config=self.config, startdir=self.startdir + ) + self._write_report_lines_from_hooks(lines) def _write_report_lines_from_hooks( self, lines: List[Union[str, List[str]]] @@ -775,7 +798,7 @@ class TerminalReporter: ExitCode.USAGE_ERROR, ExitCode.NO_TESTS_COLLECTED, ) - if exitstatus in summary_exit_codes: + if exitstatus in summary_exit_codes and self.no_summary == 0: self.config.hook.pytest_terminal_summary( terminalreporter=self, exitstatus=exitstatus, config=self.config )