Merge pull request #7258 from piotrhm/issue_6471
This commit is contained in:
commit
2c37585f58
|
@ -0,0 +1,4 @@
|
|||
New command-line flags:
|
||||
|
||||
* `--no-header`: disables the initial header, including platform, version, and plugins.
|
||||
* `--no-summary`: disables the final test summary, including warnings.
|
|
@ -117,6 +117,20 @@ def pytest_addoption(parser: Parser) -> None:
|
|||
dest="verbose",
|
||||
help="increase verbosity.",
|
||||
)
|
||||
group._addoption(
|
||||
"--no-header",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="no_header",
|
||||
help="disable header",
|
||||
)
|
||||
group._addoption(
|
||||
"--no-summary",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="no_summary",
|
||||
help="disable summary",
|
||||
)
|
||||
group._addoption(
|
||||
"-q",
|
||||
"--quiet",
|
||||
|
@ -354,6 +368,14 @@ class TerminalReporter:
|
|||
def showheader(self) -> bool:
|
||||
return self.verbosity >= 0
|
||||
|
||||
@property
|
||||
def no_header(self) -> bool:
|
||||
return bool(self.config.option.no_header)
|
||||
|
||||
@property
|
||||
def no_summary(self) -> bool:
|
||||
return bool(self.config.option.no_summary)
|
||||
|
||||
@property
|
||||
def showfspath(self) -> bool:
|
||||
if self._showfspath is None:
|
||||
|
@ -663,25 +685,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 not self.no_header:
|
||||
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]]]
|
||||
|
@ -778,7 +801,7 @@ class TerminalReporter:
|
|||
ExitCode.USAGE_ERROR,
|
||||
ExitCode.NO_TESTS_COLLECTED,
|
||||
)
|
||||
if exitstatus in summary_exit_codes:
|
||||
if exitstatus in summary_exit_codes and not self.no_summary:
|
||||
self.config.hook.pytest_terminal_summary(
|
||||
terminalreporter=self, exitstatus=exitstatus, config=self.config
|
||||
)
|
||||
|
|
|
@ -698,6 +698,29 @@ class TestTerminalFunctional:
|
|||
if request.config.pluginmanager.list_plugin_distinfo():
|
||||
result.stdout.fnmatch_lines(["plugins: *"])
|
||||
|
||||
def test_no_header_trailer_info(self, testdir, request):
|
||||
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_passes():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--no-header")
|
||||
verinfo = ".".join(map(str, sys.version_info[:3]))
|
||||
result.stdout.no_fnmatch_line(
|
||||
"platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s"
|
||||
% (
|
||||
sys.platform,
|
||||
verinfo,
|
||||
pytest.__version__,
|
||||
py.__version__,
|
||||
pluggy.__version__,
|
||||
)
|
||||
)
|
||||
if request.config.pluginmanager.list_plugin_distinfo():
|
||||
result.stdout.no_fnmatch_line("plugins: *")
|
||||
|
||||
def test_header(self, testdir):
|
||||
testdir.tmpdir.join("tests").ensure_dir()
|
||||
testdir.tmpdir.join("gui").ensure_dir()
|
||||
|
@ -727,6 +750,36 @@ class TestTerminalFunctional:
|
|||
result = testdir.runpytest("tests")
|
||||
result.stdout.fnmatch_lines(["rootdir: *test_header0, configfile: tox.ini"])
|
||||
|
||||
def test_no_header(self, testdir):
|
||||
testdir.tmpdir.join("tests").ensure_dir()
|
||||
testdir.tmpdir.join("gui").ensure_dir()
|
||||
|
||||
# with testpaths option, and not passing anything in the command-line
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
testpaths = tests gui
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--no-header")
|
||||
result.stdout.no_fnmatch_line(
|
||||
"rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"
|
||||
)
|
||||
|
||||
# with testpaths option, passing directory in command-line: do not show testpaths then
|
||||
result = testdir.runpytest("tests", "--no-header")
|
||||
result.stdout.no_fnmatch_line("rootdir: *test_header0, inifile: tox.ini")
|
||||
|
||||
def test_no_summary(self, testdir):
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
def test_no_summary():
|
||||
assert false
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest(p1, "--no-summary")
|
||||
result.stdout.no_fnmatch_line("*= FAILURES =*")
|
||||
|
||||
def test_showlocals(self, testdir):
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
|
@ -1483,6 +1536,21 @@ def test_terminal_summary_warnings_header_once(testdir):
|
|||
assert stdout.count("=== warnings summary ") == 1
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("default")
|
||||
def test_terminal_no_summary_warnings_header_once(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_failure():
|
||||
import warnings
|
||||
warnings.warn("warning_from_" + "test")
|
||||
assert 0
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--no-summary")
|
||||
result.stdout.no_fnmatch_line("*= warnings summary =*")
|
||||
result.stdout.no_fnmatch_line("*= short test summary info =*")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def tr() -> TerminalReporter:
|
||||
config = _pytest.config._prepareconfig()
|
||||
|
@ -2130,6 +2198,12 @@ def test_collecterror(testdir):
|
|||
)
|
||||
|
||||
|
||||
def test_no_summary_collecterror(testdir):
|
||||
p1 = testdir.makepyfile("raise SyntaxError()")
|
||||
result = testdir.runpytest("-ra", "--no-summary", str(p1))
|
||||
result.stdout.no_fnmatch_line("*= ERRORS =*")
|
||||
|
||||
|
||||
def test_via_exec(testdir: Testdir) -> None:
|
||||
p1 = testdir.makepyfile("exec('def test_via_exec(): pass')")
|
||||
result = testdir.runpytest(str(p1), "-vv")
|
||||
|
|
Loading…
Reference in New Issue