#1478 Added --no-stdout option

This commit is contained in:
feuillemorte 2018-01-31 22:36:28 +03:00
parent 01e37fe892
commit 949a620d3a
3 changed files with 19 additions and 0 deletions

View File

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

1
changelog/1478.trivial Normal file
View File

@ -0,0 +1 @@
Added `--no-stdout` feature. Stdout will not shown in terminal if you use this option. Only Stderr will shown.

View File

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