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
This commit is contained in:
parent
5e479c94ce
commit
93da606763
|
@ -1,6 +1,9 @@
|
||||||
Changes between 2.3.4 and 2.3.5dev
|
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
|
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0
|
||||||
|
|
||||||
- inject "getfixture()" helper to retrieve fixtures from doctests,
|
- inject "getfixture()" helper to retrieve fixtures from doctests,
|
||||||
|
|
|
@ -42,17 +42,27 @@ class DoctestItem(pytest.Item):
|
||||||
example = doctestfailure.example
|
example = doctestfailure.example
|
||||||
test = doctestfailure.test
|
test = doctestfailure.test
|
||||||
filename = test.filename
|
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__
|
message = excinfo.type.__name__
|
||||||
reprlocation = ReprFileLocation(filename, lineno, message)
|
reprlocation = ReprFileLocation(filename, lineno, message)
|
||||||
checker = py.std.doctest.OutputChecker()
|
checker = py.std.doctest.OutputChecker()
|
||||||
REPORT_UDIFF = py.std.doctest.REPORT_UDIFF
|
REPORT_UDIFF = py.std.doctest.REPORT_UDIFF
|
||||||
filelines = py.path.local(filename).readlines(cr=0)
|
filelines = py.path.local(filename).readlines(cr=0)
|
||||||
i = max(test.lineno, max(0, lineno - 10)) # XXX?
|
|
||||||
lines = []
|
lines = []
|
||||||
for line in filelines[i:lineno]:
|
if lineno is not None:
|
||||||
lines.append("%03d %s" % (i+1, line))
|
i = max(test.lineno, max(0, lineno - 10)) # XXX?
|
||||||
i += 1
|
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):
|
if excinfo.errisinstance(doctest.DocTestFailure):
|
||||||
lines += checker.output_difference(example,
|
lines += checker.output_difference(example,
|
||||||
doctestfailure.got, REPORT_UDIFF).split("\n")
|
doctestfailure.got, REPORT_UDIFF).split("\n")
|
||||||
|
|
|
@ -59,6 +59,26 @@ class TestDoctests:
|
||||||
"*UNEXPECTED*ZeroDivision*",
|
"*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):
|
def test_doctest_unex_importerror(self, testdir):
|
||||||
testdir.tmpdir.join("hello.py").write(py.code.Source("""
|
testdir.tmpdir.join("hello.py").write(py.code.Source("""
|
||||||
import asdalsdkjaslkdjasd
|
import asdalsdkjaslkdjasd
|
||||||
|
|
Loading…
Reference in New Issue