Skip to content

Commit 61c569f

Browse files
committed
Merge branch 'junit_stdout_err_on_error'
2 parents 4de3d59 + dd56d7b commit 61c569f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Erik M. Bray
3535
Florian Bruhin
3636
Floris Bruynooghe
3737
Gabriel Reis
38+
Georgy Dyuldin
3839
Graham Horler
3940
Grig Gheorghiu
4041
Guido Wesdorp

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
- fix #628: fixed internal UnicodeDecodeError when doctests contain unicode.
2727
Thanks Jason R. Coombs for the report and Bruno Oliveira for the PR.
2828

29+
- fix #1334: Add captured stdout to jUnit XML report on setup error.
30+
Thanks Georgy Dyuldin for the PR.
31+
2932

3033
2.8.5
3134
-----

_pytest/junitxml.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def append_collect_skipped(self, report):
163163
def append_error(self, report):
164164
self._add_simple(
165165
Junit.error, "test setup failure", report.longrepr)
166+
self._write_captured_output(report)
166167

167168
def append_skipped(self, report):
168169
if hasattr(report, "wasxfail"):

testing/test_junitxml.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,35 @@ def test_pass():
419419
systemout = pnode.find_first_by_tag("system-err")
420420
assert "hello-stderr" in systemout.toxml()
421421

422+
def test_setup_error_captures_stdout(self, testdir):
423+
testdir.makepyfile("""
424+
def pytest_funcarg__arg(request):
425+
print('hello-stdout')
426+
raise ValueError()
427+
def test_function(arg):
428+
pass
429+
""")
430+
result, dom = runandparse(testdir)
431+
node = dom.find_first_by_tag("testsuite")
432+
pnode = node.find_first_by_tag("testcase")
433+
systemout = pnode.find_first_by_tag("system-out")
434+
assert "hello-stdout" in systemout.toxml()
435+
436+
def test_setup_error_captures_stderr(self, testdir):
437+
testdir.makepyfile("""
438+
import sys
439+
def pytest_funcarg__arg(request):
440+
sys.stderr.write('hello-stderr')
441+
raise ValueError()
442+
def test_function(arg):
443+
pass
444+
""")
445+
result, dom = runandparse(testdir)
446+
node = dom.find_first_by_tag("testsuite")
447+
pnode = node.find_first_by_tag("testcase")
448+
systemout = pnode.find_first_by_tag("system-err")
449+
assert "hello-stderr" in systemout.toxml()
450+
422451

423452
def test_mangle_testnames():
424453
from _pytest.junitxml import mangle_testnames

0 commit comments

Comments
 (0)