stdout/stderr now captured by junitxml
This commit is contained in:
parent
94aa76fec0
commit
1cbd2db621
|
@ -173,8 +173,7 @@ class CaptureManager:
|
||||||
if funcarg_outerr is not None:
|
if funcarg_outerr is not None:
|
||||||
outerr = (outerr[0] + funcarg_outerr[0],
|
outerr = (outerr[0] + funcarg_outerr[0],
|
||||||
outerr[1] + funcarg_outerr[1])
|
outerr[1] + funcarg_outerr[1])
|
||||||
if not rep.passed:
|
addouterr(rep, outerr)
|
||||||
addouterr(rep, outerr)
|
|
||||||
if not rep.passed or rep.when == "teardown":
|
if not rep.passed or rep.when == "teardown":
|
||||||
outerr = ('', '')
|
outerr = ('', '')
|
||||||
item.outerr = outerr
|
item.outerr = outerr
|
||||||
|
|
|
@ -107,11 +107,20 @@ class LogXML(object):
|
||||||
time=getattr(report, 'duration', 0)
|
time=getattr(report, 'duration', 0)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def _write_captured_output(self, report):
|
||||||
|
sec = dict(report.sections)
|
||||||
|
for name in ('out', 'err'):
|
||||||
|
content = sec.get("Captured std%s" % name)
|
||||||
|
if content:
|
||||||
|
tag = getattr(Junit, 'system-'+name)
|
||||||
|
self.append(tag(bin_xml_escape(content)))
|
||||||
|
|
||||||
def append(self, obj):
|
def append(self, obj):
|
||||||
self.tests[-1].append(obj)
|
self.tests[-1].append(obj)
|
||||||
|
|
||||||
def append_pass(self, report):
|
def append_pass(self, report):
|
||||||
self.passed += 1
|
self.passed += 1
|
||||||
|
self._write_captured_output(report)
|
||||||
|
|
||||||
def append_failure(self, report):
|
def append_failure(self, report):
|
||||||
#msg = str(report.longrepr.reprtraceback.extraline)
|
#msg = str(report.longrepr.reprtraceback.extraline)
|
||||||
|
@ -120,16 +129,11 @@ class LogXML(object):
|
||||||
Junit.skipped(message="xfail-marked test passes unexpectedly"))
|
Junit.skipped(message="xfail-marked test passes unexpectedly"))
|
||||||
self.skipped += 1
|
self.skipped += 1
|
||||||
else:
|
else:
|
||||||
sec = dict(report.sections)
|
|
||||||
fail = Junit.failure(message="test failure")
|
fail = Junit.failure(message="test failure")
|
||||||
fail.append(str(report.longrepr))
|
fail.append(str(report.longrepr))
|
||||||
self.append(fail)
|
self.append(fail)
|
||||||
for name in ('out', 'err'):
|
|
||||||
content = sec.get("Captured std%s" % name)
|
|
||||||
if content:
|
|
||||||
tag = getattr(Junit, 'system-'+name)
|
|
||||||
self.append(tag(bin_xml_escape(content)))
|
|
||||||
self.failed += 1
|
self.failed += 1
|
||||||
|
self._write_captured_output(report)
|
||||||
|
|
||||||
def append_collect_failure(self, report):
|
def append_collect_failure(self, report):
|
||||||
#msg = str(report.longrepr.reprtraceback.extraline)
|
#msg = str(report.longrepr.reprtraceback.extraline)
|
||||||
|
@ -162,6 +166,7 @@ class LogXML(object):
|
||||||
message=skipreason
|
message=skipreason
|
||||||
))
|
))
|
||||||
self.skipped += 1
|
self.skipped += 1
|
||||||
|
self._write_captured_output(report)
|
||||||
|
|
||||||
def pytest_runtest_logreport(self, report):
|
def pytest_runtest_logreport(self, report):
|
||||||
if report.passed:
|
if report.passed:
|
||||||
|
|
|
@ -282,13 +282,35 @@ class TestPython:
|
||||||
if not sys.platform.startswith("java"):
|
if not sys.platform.startswith("java"):
|
||||||
assert "hx" in fnode.toxml()
|
assert "hx" in fnode.toxml()
|
||||||
|
|
||||||
|
def test_pass_captures_stdout(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def test_pass():
|
||||||
|
print('hello-stdout')
|
||||||
|
""")
|
||||||
|
result, dom = runandparse(testdir)
|
||||||
|
node = dom.getElementsByTagName("testsuite")[0]
|
||||||
|
pnode = node.getElementsByTagName("testcase")[0]
|
||||||
|
systemout = pnode.getElementsByTagName("system-out")[0]
|
||||||
|
assert "hello-stdout" in systemout.toxml()
|
||||||
|
|
||||||
|
def test_pass_captures_stderr(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import sys
|
||||||
|
def test_pass():
|
||||||
|
sys.stderr.write('hello-stderr')
|
||||||
|
""")
|
||||||
|
result, dom = runandparse(testdir)
|
||||||
|
node = dom.getElementsByTagName("testsuite")[0]
|
||||||
|
pnode = node.getElementsByTagName("testcase")[0]
|
||||||
|
systemout = pnode.getElementsByTagName("system-err")[0]
|
||||||
|
assert "hello-stderr" in systemout.toxml()
|
||||||
|
|
||||||
def test_mangle_testnames():
|
def test_mangle_testnames():
|
||||||
from _pytest.junitxml import mangle_testnames
|
from _pytest.junitxml import mangle_testnames
|
||||||
names = ["a/pything.py", "Class", "()", "method"]
|
names = ["a/pything.py", "Class", "()", "method"]
|
||||||
newnames = mangle_testnames(names)
|
newnames = mangle_testnames(names)
|
||||||
assert newnames == ["a.pything", "Class", "method"]
|
assert newnames == ["a.pything", "Class", "method"]
|
||||||
|
|
||||||
|
|
||||||
def test_dont_configure_on_slaves(tmpdir):
|
def test_dont_configure_on_slaves(tmpdir):
|
||||||
gotten = []
|
gotten = []
|
||||||
class FakeConfig:
|
class FakeConfig:
|
||||||
|
|
Loading…
Reference in New Issue