#1478 Added --show-capture=both option (fix comments)

This commit is contained in:
feuillemorte 2018-02-08 16:21:22 +03:00
parent 1a650a9eb9
commit 71367881ed
3 changed files with 16 additions and 8 deletions

View File

@ -44,8 +44,9 @@ def pytest_addoption(parser):
help="traceback print mode (auto/long/short/line/native/no).")
group._addoption('--show-capture',
action="store", dest="showcapture",
choices=['no', 'stdout', 'stderr'],
help="Print only stdout/stderr on not print both.")
choices=['no', 'stdout', 'stderr', 'both'], default='both',
help="Controls how captured stdout/stderr is shown on failed tests. "
"Default is 'both'.")
group._addoption('--fulltrace', '--full-trace',
action="store_true", default=False,
help="don't cut any tracebacks (default is to cut).")
@ -629,8 +630,10 @@ class TerminalReporter:
if self.config.option.showcapture == 'no':
return
for secname, content in rep.sections:
if self.config.option.showcapture and not (self.config.option.showcapture in secname):
continue
print(self.config.option.showcapture)
if self.config.option.showcapture != 'both':
if not (self.config.option.showcapture in secname):
continue
self._tw.sep("-", secname)
if content[-1:] == "\n":
content = content[:-1]

View File

@ -1,4 +1 @@
Added `--show-capture` feature. You can choose 'no', 'stdout' or 'stderr' option.
'no': stdout and stderr will now shown
'stdout': stdout will shown in terminal if you use this option but stderr will not shown.
'stderr': stderr will shown in terminal if you use this option but stdout will not shown.
New ``--show-capture`` command-line option that allows to specify how to display captured output when tests fail: ``no``, ``stdout``, ``stderr`` or ``both`` (the default).

View File

@ -836,6 +836,10 @@ def pytest_report_header(config, startdir):
result.stdout.fnmatch_lines(["!This is stdout!"])
result.stdout.fnmatch_lines(["!This is stderr!"])
result = testdir.runpytest("--show-capture=both", "--tb=short")
result.stdout.fnmatch_lines(["!This is stdout!"])
result.stdout.fnmatch_lines(["!This is stderr!"])
result = testdir.runpytest("--show-capture=stdout", "--tb=short")
assert "!This is stderr!" not in result.stdout.str()
assert "!This is stdout!" in result.stdout.str()
@ -844,6 +848,10 @@ def pytest_report_header(config, startdir):
assert "!This is stdout!" not in result.stdout.str()
assert "!This is stderr!" in result.stdout.str()
result = testdir.runpytest("--show-capture=no", "--tb=short")
assert "!This is stdout!" not in result.stdout.str()
assert "!This is stderr!" not in result.stdout.str()
@pytest.mark.xfail("not hasattr(os, 'dup')")
def test_fdopen_kept_alive_issue124(testdir):