Added requested modifications

This commit is contained in:
piotrhm 2020-05-25 14:18:57 +02:00 committed by Bruno Oliveira
parent fcbaab8b0b
commit 0b70300ba4
3 changed files with 45 additions and 20 deletions

View File

@ -227,6 +227,7 @@ Pedro Algarvio
Philipp Loose
Pieter Mulder
Piotr Banaszkiewicz
Piotr Helm
Prashant Anand
Pulkit Goyal
Punyashloka Biswal

View File

@ -0,0 +1 @@
New flags --no-header and --no-summary added. The first one disables header, the second one disables summary.

View File

@ -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
)