Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3491 - Fixed a bug where stdout and stderr were logged twice by junitxml for xfail tests. #3499

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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