From 0b0406fa858c6a71164bc28660c99ef244096f37 Mon Sep 17 00:00:00 2001 From: Punyashloka Biswal Date: Tue, 16 Jun 2015 16:35:31 -0400 Subject: [PATCH] Handle reports that don't have a reprcrash Closes #713 (which happens because ReprFailDoctest doesn't have a reprcrash) --- AUTHORS | 1 + CHANGELOG | 3 +++ _pytest/junitxml.py | 6 ++++-- testing/test_doctest.py | 13 +++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index e0b61fa5d..a24447c33 100644 --- a/AUTHORS +++ b/AUTHORS @@ -43,6 +43,7 @@ Mark Abramowitz Martijn Faassen Nicolas Delaby Piotr Banaszkiewicz +Punyashloka Biswal Ralf Schmitt Ronny Pfannschmidt Ross Lawley diff --git a/CHANGELOG b/CHANGELOG index 0cefc9181..b0281d291 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 2.8.0.dev (compared to 2.7.X) ----------------------------- +- fix issue713: JUnit XML reports for doctest failures. + Thanks Punyashloka Biswal. + - Include setup and teardown in junitxml test durations. Thanks Janne Vanhala. diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 3553a19ec..bcdf85781 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -123,10 +123,12 @@ class LogXML(object): Junit.skipped(message="xfail-marked test passes unexpectedly")) self.skipped += 1 else: - if isinstance(report.longrepr, (unicode, str)): + if hasattr(report.longrepr, "reprcrash"): + message = report.longrepr.reprcrash.message + elif isinstance(report.longrepr, (unicode, str)): message = report.longrepr else: - message = report.longrepr.reprcrash.message + message = str(report.longrepr) message = bin_xml_escape(message) fail = Junit.failure(message=message) fail.append(bin_xml_escape(report.longrepr)) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 3b0bb6868..f740b8484 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -352,3 +352,16 @@ class TestDoctests: reprec = testdir.inline_run(p, "--doctest-modules", "--doctest-ignore-import-errors") reprec.assertoutcome(skipped=1, failed=1, passed=0) + + def test_junit_report_for_doctest(self, testdir): + p = testdir.makepyfile(""" + def foo(): + ''' + >>> 1 + 1 + 3 + ''' + pass + """) + reprec = testdir.inline_run(p, "--doctest-modules", + "--junit-xml=junit.xml") + reprec.assertoutcome(failed=1)