From b28b3cc271fcd5bff672b62bf3ab9eacffabc1b1 Mon Sep 17 00:00:00 2001 From: Georgy Dyuldin Date: Wed, 20 Jan 2016 20:13:01 +0300 Subject: [PATCH] Add captured stdout to jUnit report on setup error --- _pytest/junitxml.py | 1 + testing/test_junitxml.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 995694687..b0c2b4d3a 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -163,6 +163,7 @@ class _NodeReporter(object): def append_error(self, report): self._add_simple( Junit.error, "test setup failure", report.longrepr) + self._write_captured_output(report) def append_skipped(self, report): if hasattr(report, "wasxfail"): diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 0062ab135..e6db81051 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -419,6 +419,35 @@ class TestPython: systemout = pnode.find_first_by_tag("system-err") assert "hello-stderr" in systemout.toxml() + def test_setup_error_captures_stdout(self, testdir): + testdir.makepyfile(""" + def pytest_funcarg__arg(request): + print('hello-stdout') + raise ValueError() + def test_function(arg): + pass + """) + result, dom = runandparse(testdir) + node = dom.find_first_by_tag("testsuite") + pnode = node.find_first_by_tag("testcase") + systemout = pnode.find_first_by_tag("system-out") + assert "hello-stdout" in systemout.toxml() + + def test_setup_error_captures_stderr(self, testdir): + testdir.makepyfile(""" + import sys + def pytest_funcarg__arg(request): + sys.stderr.write('hello-stderr') + raise ValueError() + def test_function(arg): + pass + """) + result, dom = runandparse(testdir) + node = dom.find_first_by_tag("testsuite") + pnode = node.find_first_by_tag("testcase") + systemout = pnode.find_first_by_tag("system-err") + assert "hello-stderr" in systemout.toxml() + def test_mangle_testnames(): from _pytest.junitxml import mangle_testnames