Skip to content

Commit 0b0406f

Browse files
punyaPunya Biswal
authored and
Punya Biswal
committed
Handle reports that don't have a reprcrash
Closes #713 (which happens because ReprFailDoctest doesn't have a reprcrash)
1 parent f1245b0 commit 0b0406f

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Mark Abramowitz
4343
Martijn Faassen
4444
Nicolas Delaby
4545
Piotr Banaszkiewicz
46+
Punyashloka Biswal
4647
Ralf Schmitt
4748
Ronny Pfannschmidt
4849
Ross Lawley

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
2.8.0.dev (compared to 2.7.X)
22
-----------------------------
33

4+
- fix issue713: JUnit XML reports for doctest failures.
5+
Thanks Punyashloka Biswal.
6+
47
- Include setup and teardown in junitxml test durations.
58
Thanks Janne Vanhala.
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,16 @@ def add_one(x):
352352
reprec = testdir.inline_run(p, "--doctest-modules",
353353
"--doctest-ignore-import-errors")
354354
reprec.assertoutcome(skipped=1, failed=1, passed=0)
355+
356+
def test_junit_report_for_doctest(self, testdir):
357+
p = testdir.makepyfile("""
358+
def foo():
359+
'''
360+
>>> 1 + 1
361+
3
362+
'''
363+
pass
364+
""")
365+
reprec = testdir.inline_run(p, "--doctest-modules",
366+
"--junit-xml=junit.xml")
367+
reprec.assertoutcome(failed=1)

0 commit comments

Comments
 (0)