1 new commit in pytest: https://bitbucket.org/hpk42/pytest/commits/8908cc8650ff/ Changeset: 8908cc8650ff User: RonnyPfannschmidt Date: 2013-03-24 20:05:29 Summary: fix Issue 274 - dont fail when doctest does not know the example location
instead only the last test is shown, this could use some further enhancement Affected #: 3 files diff -r 3bd27c424613a79e529359063c90fd36309b331c -r 8908cc8650ff538acbfa175a5d5e07effa140c23 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.3.4 and 2.3.5dev ----------------------------------- +- Issue 274 - dont try to show full doctest example + when doctest does not know the example location + - issue 280 - disable assertion rewriting on buggy CPython 2.6.0 - inject "getfixture()" helper to retrieve fixtures from doctests, diff -r 3bd27c424613a79e529359063c90fd36309b331c -r 8908cc8650ff538acbfa175a5d5e07effa140c23 _pytest/doctest.py --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -42,17 +42,27 @@ example = doctestfailure.example test = doctestfailure.test filename = test.filename - lineno = test.lineno + example.lineno + 1 + if test.lineno is None: + lineno = None + else: + lineno = test.lineno + example.lineno + 1 message = excinfo.type.__name__ reprlocation = ReprFileLocation(filename, lineno, message) checker = py.std.doctest.OutputChecker() REPORT_UDIFF = py.std.doctest.REPORT_UDIFF filelines = py.path.local(filename).readlines(cr=0) - i = max(test.lineno, max(0, lineno - 10)) # XXX? lines = [] - for line in filelines[i:lineno]: - lines.append("%03d %s" % (i+1, line)) - i += 1 + if lineno is not None: + i = max(test.lineno, max(0, lineno - 10)) # XXX? + for line in filelines[i:lineno]: + lines.append("%03d %s" % (i+1, line)) + i += 1 + else: + lines.append('EXAMPLE LOCATION UNKNOWN, not showing all tests of that example') + indent = '>>>' + for line in example.source.splitlines(): + lines.append('??? %s %s' % (indent, line)) + indent = '...' if excinfo.errisinstance(doctest.DocTestFailure): lines += checker.output_difference(example, doctestfailure.got, REPORT_UDIFF).split("\n") diff -r 3bd27c424613a79e529359063c90fd36309b331c -r 8908cc8650ff538acbfa175a5d5e07effa140c23 testing/test_doctest.py --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -59,6 +59,26 @@ "*UNEXPECTED*ZeroDivision*", ]) + def test_doctest_linedata_missing(self, testdir): + testdir.tmpdir.join('hello.py').write(py.code.Source(""" + class Fun(object): + @property + def test(self): + ''' + >>> a = 1 + >>> 1/0 + ''' + """)) + result = testdir.runpytest("--doctest-modules") + result.stdout.fnmatch_lines([ + "*hello*", + "*EXAMPLE LOCATION UNKNOWN, not showing all tests of that example*", + "*1/0*", + "*UNEXPECTED*ZeroDivision*", + "*1 failed*", + ]) + + def test_doctest_unex_importerror(self, testdir): testdir.tmpdir.join("hello.py").write(py.code.Source(""" import asdalsdkjaslkdjasd Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org http://mail.python.org/mailman/listinfo/pytest-commit