parent
08002ab75a
commit
ff296fd541
|
@ -118,13 +118,10 @@ class _NodeReporter(object):
|
||||||
|
|
||||||
def _write_captured_output(self, report):
|
def _write_captured_output(self, report):
|
||||||
for capname in ('out', 'err'):
|
for capname in ('out', 'err'):
|
||||||
allcontent = ""
|
content = getattr(report, 'capstd' + capname)
|
||||||
for name, content in report.get_sections("Captured std%s" %
|
if content:
|
||||||
capname):
|
|
||||||
allcontent += content
|
|
||||||
if allcontent:
|
|
||||||
tag = getattr(Junit, 'system-' + capname)
|
tag = getattr(Junit, 'system-' + capname)
|
||||||
self.append(tag(bin_xml_escape(allcontent)))
|
self.append(tag(bin_xml_escape(content)))
|
||||||
|
|
||||||
def append_pass(self, report):
|
def append_pass(self, report):
|
||||||
self.add_stats('passed')
|
self.add_stats('passed')
|
||||||
|
|
|
@ -225,6 +225,22 @@ class BaseReport(object):
|
||||||
exc = tw.stringio.getvalue()
|
exc = tw.stringio.getvalue()
|
||||||
return exc.strip()
|
return exc.strip()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def capstdout(self):
|
||||||
|
"""Return captured text from stdout, if capturing is enabled
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
"""
|
||||||
|
return ''.join(content for (prefix, content) in self.get_sections('Captured stdout'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def capstderr(self):
|
||||||
|
"""Return captured text from stderr, if capturing is enabled
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
"""
|
||||||
|
return ''.join(content for (prefix, content) in self.get_sections('Captured stderr'))
|
||||||
|
|
||||||
passed = property(lambda x: x.outcome == "passed")
|
passed = property(lambda x: x.outcome == "passed")
|
||||||
failed = property(lambda x: x.outcome == "failed")
|
failed = property(lambda x: x.outcome == "failed")
|
||||||
skipped = property(lambda x: x.outcome == "skipped")
|
skipped = property(lambda x: x.outcome == "skipped")
|
||||||
|
|
|
@ -672,10 +672,13 @@ def test_store_except_info_on_eror():
|
||||||
|
|
||||||
class TestReportContents:
|
class TestReportContents:
|
||||||
"""
|
"""
|
||||||
Test ``longreprtext`` property of TestReport objects.
|
Test user-level API of ``TestReport`` objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_pass(self, testdir):
|
def getrunner(self):
|
||||||
|
return lambda item: runner.runtestprotocol(item, log=False)
|
||||||
|
|
||||||
|
def test_longreprtext_pass(self, testdir):
|
||||||
reports = testdir.runitem("""
|
reports = testdir.runitem("""
|
||||||
def test_func():
|
def test_func():
|
||||||
pass
|
pass
|
||||||
|
@ -683,7 +686,7 @@ class TestReportContents:
|
||||||
rep = reports[1]
|
rep = reports[1]
|
||||||
assert rep.longreprtext == ''
|
assert rep.longreprtext == ''
|
||||||
|
|
||||||
def test_failure(self, testdir):
|
def test_longreprtext_failure(self, testdir):
|
||||||
reports = testdir.runitem("""
|
reports = testdir.runitem("""
|
||||||
def test_func():
|
def test_func():
|
||||||
x = 1
|
x = 1
|
||||||
|
@ -692,5 +695,41 @@ class TestReportContents:
|
||||||
rep = reports[1]
|
rep = reports[1]
|
||||||
assert 'assert 1 == 4' in rep.longreprtext
|
assert 'assert 1 == 4' in rep.longreprtext
|
||||||
|
|
||||||
def getrunner(self):
|
def test_captured_text(self, testdir):
|
||||||
return lambda item: runner.runtestprotocol(item, log=False)
|
reports = testdir.runitem("""
|
||||||
|
import pytest
|
||||||
|
import sys
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def fix():
|
||||||
|
sys.stdout.write('setup: stdout\\n')
|
||||||
|
sys.stderr.write('setup: stderr\\n')
|
||||||
|
yield
|
||||||
|
sys.stdout.write('teardown: stdout\\n')
|
||||||
|
sys.stderr.write('teardown: stderr\\n')
|
||||||
|
assert 0
|
||||||
|
|
||||||
|
def test_func(fix):
|
||||||
|
sys.stdout.write('call: stdout\\n')
|
||||||
|
sys.stderr.write('call: stderr\\n')
|
||||||
|
assert 0
|
||||||
|
""")
|
||||||
|
setup, call, teardown = reports
|
||||||
|
assert setup.capstdout == 'setup: stdout\n'
|
||||||
|
assert call.capstdout == 'setup: stdout\ncall: stdout\n'
|
||||||
|
assert teardown.capstdout == 'setup: stdout\ncall: stdout\nteardown: stdout\n'
|
||||||
|
|
||||||
|
assert setup.capstderr == 'setup: stderr\n'
|
||||||
|
assert call.capstderr == 'setup: stderr\ncall: stderr\n'
|
||||||
|
assert teardown.capstderr == 'setup: stderr\ncall: stderr\nteardown: stderr\n'
|
||||||
|
|
||||||
|
def test_no_captured_text(self, testdir):
|
||||||
|
reports = testdir.runitem("""
|
||||||
|
def test_func():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
rep = reports[1]
|
||||||
|
assert rep.capstdout == ''
|
||||||
|
assert rep.capstderr == ''
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue