diff --git a/AUTHORS b/AUTHORS index 625e8535a..7b22002d1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -35,6 +35,7 @@ Erik M. Bray Florian Bruhin Floris Bruynooghe Gabriel Reis +Georgy Dyuldin Graham Horler Grig Gheorghiu Guido Wesdorp diff --git a/CHANGELOG b/CHANGELOG index 6e3a73a49..3dd62dd22 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,9 @@ - fix #628: fixed internal UnicodeDecodeError when doctests contain unicode. Thanks Jason R. Coombs for the report and Bruno Oliveira for the PR. +- fix #1334: Add captured stdout to jUnit XML report on setup error. + Thanks Georgy Dyuldin for the PR. + 2.8.5 ----- 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