#1478 Added --show-capture option
This commit is contained in:
parent
949a620d3a
commit
1a650a9eb9
|
@ -42,9 +42,10 @@ 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('--no-stdout',
|
group._addoption('--show-capture',
|
||||||
action="store_false", dest="nostdout",
|
action="store", dest="showcapture",
|
||||||
help="Do not print stdout")
|
choices=['no', 'stdout', 'stderr'],
|
||||||
|
help="Print only stdout/stderr on not print 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).")
|
||||||
|
@ -625,8 +626,10 @@ class TerminalReporter:
|
||||||
|
|
||||||
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 not self.config.option.nostdout and 'stdout' in secname:
|
if self.config.option.showcapture and not (self.config.option.showcapture in secname):
|
||||||
continue
|
continue
|
||||||
self._tw.sep("-", secname)
|
self._tw.sep("-", secname)
|
||||||
if content[-1:] == "\n":
|
if content[-1:] == "\n":
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
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.
|
|
@ -1 +0,0 @@
|
||||||
Added `--no-stdout` feature. Stdout will not shown in terminal if you use this option. Only Stderr will shown.
|
|
|
@ -823,18 +823,26 @@ def pytest_report_header(config, startdir):
|
||||||
str(testdir.tmpdir),
|
str(testdir.tmpdir),
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_no_stdout(self, testdir):
|
def test_show_capture(self, testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
import sys
|
||||||
def test_one():
|
def test_one():
|
||||||
print('!This is stdout!')
|
sys.stdout.write('!This is stdout!')
|
||||||
|
sys.stderr.write('!This is stderr!')
|
||||||
assert False, 'Something failed'
|
assert False, 'Something failed'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
result = testdir.runpytest("--tb=short")
|
result = testdir.runpytest("--tb=short")
|
||||||
result.stdout.fnmatch_lines(["!This is stdout!"])
|
result.stdout.fnmatch_lines(["!This is stdout!"])
|
||||||
|
result.stdout.fnmatch_lines(["!This is stderr!"])
|
||||||
|
|
||||||
result = testdir.runpytest("--no-stdout", "--tb=short")
|
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 stdout!" not in result.stdout.str()
|
||||||
|
assert "!This is stderr!" in result.stdout.str()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
||||||
|
|
Loading…
Reference in New Issue