Merge pull request #3176 from feuillemorte/1478_no_stdout_option
#1478 Added --no-stdout option
This commit is contained in:
commit
063e2da967
|
@ -42,6 +42,11 @@ def pytest_addoption(parser):
|
||||||
action="store", dest="tbstyle", default='auto',
|
action="store", dest="tbstyle", default='auto',
|
||||||
choices=['auto', 'long', 'short', 'no', 'line', 'native'],
|
choices=['auto', 'long', 'short', 'no', 'line', 'native'],
|
||||||
help="traceback print mode (auto/long/short/line/native/no).")
|
help="traceback print mode (auto/long/short/line/native/no).")
|
||||||
|
group._addoption('--show-capture',
|
||||||
|
action="store", dest="showcapture",
|
||||||
|
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',
|
group._addoption('--fulltrace', '--full-trace',
|
||||||
action="store_true", default=False,
|
action="store_true", default=False,
|
||||||
help="don't cut any tracebacks (default is to cut).")
|
help="don't cut any tracebacks (default is to cut).")
|
||||||
|
@ -622,7 +627,12 @@ class TerminalReporter(object):
|
||||||
|
|
||||||
def _outrep_summary(self, rep):
|
def _outrep_summary(self, rep):
|
||||||
rep.toterminal(self._tw)
|
rep.toterminal(self._tw)
|
||||||
|
if self.config.option.showcapture == 'no':
|
||||||
|
return
|
||||||
for secname, content in rep.sections:
|
for secname, content in rep.sections:
|
||||||
|
if self.config.option.showcapture != 'both':
|
||||||
|
if not (self.config.option.showcapture in secname):
|
||||||
|
continue
|
||||||
self._tw.sep("-", secname)
|
self._tw.sep("-", secname)
|
||||||
if content[-1:] == "\n":
|
if content[-1:] == "\n":
|
||||||
content = content[:-1]
|
content = content[:-1]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
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).
|
|
@ -9,7 +9,8 @@ Default stdout/stderr/stdin capturing behaviour
|
||||||
|
|
||||||
During test execution any output sent to ``stdout`` and ``stderr`` is
|
During test execution any output sent to ``stdout`` and ``stderr`` is
|
||||||
captured. If a test or a setup method fails its according captured
|
captured. If a test or a setup method fails its according captured
|
||||||
output will usually be shown along with the failure traceback.
|
output will usually be shown along with the failure traceback. (this
|
||||||
|
behavior can be configured by the ``--show-capture`` command-line option).
|
||||||
|
|
||||||
In addition, ``stdin`` is set to a "null" object which will
|
In addition, ``stdin`` is set to a "null" object which will
|
||||||
fail on attempts to read from it because it is rarely desired
|
fail on attempts to read from it because it is rarely desired
|
||||||
|
|
|
@ -823,6 +823,35 @@ def pytest_report_header(config, startdir):
|
||||||
str(testdir.tmpdir),
|
str(testdir.tmpdir),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_show_capture(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import sys
|
||||||
|
def test_one():
|
||||||
|
sys.stdout.write('!This is stdout!')
|
||||||
|
sys.stderr.write('!This is stderr!')
|
||||||
|
assert False, 'Something failed'
|
||||||
|
""")
|
||||||
|
|
||||||
|
result = testdir.runpytest("--tb=short")
|
||||||
|
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()
|
||||||
|
|
||||||
|
result = testdir.runpytest("--show-capture=stderr", "--tb=short")
|
||||||
|
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')")
|
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
||||||
def test_fdopen_kept_alive_issue124(testdir):
|
def test_fdopen_kept_alive_issue124(testdir):
|
||||||
|
|
Loading…
Reference in New Issue