diff --git a/_pytest/terminal.py b/_pytest/terminal.py index f0a2fa618..7f42f1284 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -42,6 +42,9 @@ def pytest_addoption(parser): action="store", dest="tbstyle", default='auto', choices=['auto', 'long', 'short', 'no', 'line', 'native'], help="traceback print mode (auto/long/short/line/native/no).") + group._addoption('--no-stdout', + action="store_false", dest="nostdout", + help="Do not print stdout") group._addoption('--fulltrace', '--full-trace', action="store_true", default=False, help="don't cut any tracebacks (default is to cut).") @@ -623,6 +626,8 @@ class TerminalReporter: def _outrep_summary(self, rep): rep.toterminal(self._tw) for secname, content in rep.sections: + if not self.config.option.nostdout and 'stdout' in secname: + continue self._tw.sep("-", secname) if content[-1:] == "\n": content = content[:-1] diff --git a/changelog/1478.trivial b/changelog/1478.trivial new file mode 100644 index 000000000..aa88151e7 --- /dev/null +++ b/changelog/1478.trivial @@ -0,0 +1 @@ +Added `--no-stdout` feature. Stdout will not shown in terminal if you use this option. Only Stderr will shown. \ No newline at end of file diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 7dfa4b01e..bedd6a9a5 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -823,6 +823,19 @@ def pytest_report_header(config, startdir): str(testdir.tmpdir), ]) + def test_no_stdout(self, testdir): + testdir.makepyfile(""" + def test_one(): + print('!This is stdout!') + assert False, 'Something failed' + """) + + result = testdir.runpytest("--tb=short") + result.stdout.fnmatch_lines(["!This is stdout!"]) + + result = testdir.runpytest("--no-stdout", "--tb=short") + assert "!This is stdout!" not in result.stdout.str() + @pytest.mark.xfail("not hasattr(os, 'dup')") def test_fdopen_kept_alive_issue124(testdir):