diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 3a0e4a071..a4603529b 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -224,7 +224,7 @@ class _NodeReporter(object): Junit.skipped("%s:%s: %s" % (filename, lineno, skipreason), type="pytest.skip", message=skipreason)) - self.write_captured_output(report) + self.write_captured_output(report) def finalize(self): data = self.to_xml().unicode(indent=0) diff --git a/changelog/3491.bugfix.rst b/changelog/3491.bugfix.rst new file mode 100644 index 000000000..7c8bd191c --- /dev/null +++ b/changelog/3491.bugfix.rst @@ -0,0 +1 @@ +Fixed a bug where stdout and stderr were logged twice by junitxml. \ No newline at end of file diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index a8f5b9fec..255a68a52 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -458,6 +458,23 @@ class TestPython(object): fnode.assert_attr(message="expected test failure") # assert "ValueError" in fnode.toxml() + def test_xfail_captures_output_once(self, testdir): + testdir.makepyfile(""" + import sys + import pytest + + @pytest.mark.xfail() + def test_fail(): + sys.stdout.write('XFAIL This is stdout') + sys.stderr.write('XFAIL This is stderr') + assert 0 + """) + result, dom = runandparse(testdir) + node = dom.find_first_by_tag("testsuite") + tnode = node.find_first_by_tag("testcase") + assert len(tnode.find_by_tag('system-err')) == 1 + assert len(tnode.find_by_tag('system-out')) == 1 + def test_xfailure_xpass(self, testdir): testdir.makepyfile(""" import pytest