Skip to content

Commit

Permalink
Merge pull request #3499 from jeffreyrack/3491-junit-logging
Browse files Browse the repository at this point in the history
3491 - Fixed a bug where stdout and stderr were logged twice by junitxml for xfail tests.
  • Loading branch information
nicoddemus authored May 24, 2018
2 parents 48215fd + b4e0265 commit 93fdad2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def append_skipped(self, report):
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)
Expand Down
1 change: 1 addition & 0 deletions changelog/3491.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug where stdout and stderr were logged twice by junitxml when a test was marked xfail.
17 changes: 17 additions & 0 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ def test_xfail():
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
Expand Down

0 comments on commit 93fdad2

Please sign in to comment.