From 6167ba89232e0bc3fdfe0e563ce8bd3c3c95b0a1 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 1 Jul 2009 14:24:19 +0100 Subject: [PATCH] (radomir, holger) tweak doctest reporting for docstrings from python modules --HG-- branch : 1.0.x --- py/test/plugin/pytest_doctest.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/py/test/plugin/pytest_doctest.py b/py/test/plugin/pytest_doctest.py index 2189612a5..2e51a4bfe 100644 --- a/py/test/plugin/pytest_doctest.py +++ b/py/test/plugin/pytest_doctest.py @@ -39,13 +39,13 @@ class DoctestItem(py.test.collect.Item): example = doctestfailure.example test = doctestfailure.test filename = test.filename - lineno = example.lineno + 1 + lineno = test.lineno + example.lineno + 1 message = excinfo.type.__name__ reprlocation = ReprFileLocation(filename, lineno, message) checker = py.compat.doctest.OutputChecker() REPORT_UDIFF = py.compat.doctest.REPORT_UDIFF filelines = py.path.local(filename).readlines(cr=0) - i = max(0, lineno - 10) + i = max(test.lineno, max(0, lineno - 10)) # XXX? lines = [] for line in filelines[i:lineno]: lines.append("%03d %s" % (i+1, line)) @@ -140,6 +140,28 @@ class TestDoctests: reprec = testdir.inline_run(p, "--doctest-modules") reprec.assertoutcome(failed=1) + def test_doctestmodule_external(self, testdir): + p = testdir.makepyfile(""" + # + def somefunc(): + ''' + >>> i = 0 + >>> i + 1 + 2 + ''' + """) + result = testdir.runpytest(p, "--doctest-modules") + result.stdout.fnmatch_lines([ + '004 *>>> i = 0', + '005 *>>> i + 1', + '*Expected:', + "* 2", + "*Got:", + "* 1", + "*:5: DocTestFailure" + ]) + + def test_txtfile_failing(self, testdir): p = testdir.maketxtfile(""" >>> i = 0