From 410438f1873552ff095b9baa1d40d572f468cd7d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 28 May 2011 14:38:15 +0200 Subject: [PATCH] fix issue43 - better tracebacks for unexpected exceptions in doctests --- CHANGELOG | 2 ++ _pytest/doctest.py | 2 +- testing/test_doctest.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b051e2067..0172c53ad 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 2.0.3 and DEV ---------------------------------------------- +- fix issue43: improve doctests with better traceback reporting on + unexpected exceptions - fix issue47: timing output in junitxml for test cases is now correct - introduce XXX pytest_configure_funcargs hack (thanks Ronny) - env/username expansion for junitxml file path (fixes issue44) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index 1378544ba..aaebab78e 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -59,7 +59,7 @@ class DoctestItem(pytest.Item): inner_excinfo = py.code.ExceptionInfo(excinfo.value.exc_info) lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)] - + lines += py.std.traceback.format_exception(*excinfo.value.exc_info) return ReprFailDoctest(reprlocation, lines) else: return super(DoctestItem, self).repr_failure(excinfo) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index ed9cca9fd..67dc7fdbf 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -59,6 +59,21 @@ class TestDoctests: "*UNEXPECTED*ZeroDivision*", ]) + def test_doctest_unex_importerror(self, testdir): + testdir.tmpdir.join("hello.py").write(py.code.Source(""" + import asdalsdkjaslkdjasd + """)) + p = testdir.maketxtfile(""" + >>> import hello + >>> + """) + result = testdir.runpytest("--doctest-modules") + result.stdout.fnmatch_lines([ + "*>>> import hello", + "*UNEXPECTED*ImportError*", + "*import asdals*", + ]) + def test_doctestmodule(self, testdir): p = testdir.makepyfile(""" '''