Skip to content

Commit 0c05b90

Browse files
punyanicoddemus
authored andcommitted
backport fix for #713
1 parent f04e01f commit 0c05b90

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Mark Abramowitz
4141
Martijn Faassen
4242
Nicolas Delaby
4343
Piotr Banaszkiewicz
44+
Punyashloka Biswal
4445
Ralf Schmitt
4546
Ronny Pfannschmidt
4647
Ross Lawley

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
2.7.2 (compared to 2.7.1)
22
-----------------------------
33

4+
- fix issue713: JUnit XML reports for doctest failures.
5+
Thanks Punyashloka Biswal.
6+
47
- fix issue735: assertion failures on debug versions of Python 3.4+
58
Thanks Benjamin Peterson.
69

_pytest/junitxml.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ def append_failure(self, report):
123123
Junit.skipped(message="xfail-marked test passes unexpectedly"))
124124
self.skipped += 1
125125
else:
126-
if isinstance(report.longrepr, (unicode, str)):
126+
if hasattr(report.longrepr, "reprcrash"):
127+
message = report.longrepr.reprcrash.message
128+
elif isinstance(report.longrepr, (unicode, str)):
127129
message = report.longrepr
128130
else:
129-
message = report.longrepr.reprcrash.message
131+
message = str(report.longrepr)
130132
message = bin_xml_escape(message)
131133
fail = Junit.failure(message=message)
132134
fail.append(bin_xml_escape(report.longrepr))

testing/test_doctest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,19 @@ def add_one(x):
354354
reprec = testdir.inline_run(p, "--doctest-modules",
355355
"--doctest-ignore-import-errors")
356356
reprec.assertoutcome(skipped=1, failed=1, passed=0)
357+
358+
def test_junit_report_for_doctest(self, testdir):
359+
"""
360+
#713: Fix --junit-xml option when used with --doctest-modules.
361+
"""
362+
p = testdir.makepyfile("""
363+
def foo():
364+
'''
365+
>>> 1 + 1
366+
3
367+
'''
368+
pass
369+
""")
370+
reprec = testdir.inline_run(p, "--doctest-modules",
371+
"--junit-xml=junit.xml")
372+
reprec.assertoutcome(failed=1)

0 commit comments

Comments
 (0)