fix issue7 - assert failure inside doctest doesn't prettyprint
unexpected exceptions are now reported within the doctest failure representation context.
This commit is contained in:
parent
feea4ea3d5
commit
fc4f72cb1f
|
@ -1,6 +1,9 @@
|
||||||
Changes between 2.0.0 and 2.0.1.dev1
|
Changes between 2.0.0 and 2.0.1.dev1
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
- fix issue10: assert failures in doctest modules.
|
||||||
|
unexpected failures in doctests will not generally
|
||||||
|
show nicer, i.e. within the doctest failing context.
|
||||||
- fix issue9: setup/teardown functions for an xfail-marked
|
- fix issue9: setup/teardown functions for an xfail-marked
|
||||||
test will report as xfail if they fail but report as normally
|
test will report as xfail if they fail but report as normally
|
||||||
passing (not xpassing) if they succeed. This only is true
|
passing (not xpassing) if they succeed. This only is true
|
||||||
|
|
|
@ -34,7 +34,9 @@ class ReprFailDoctest(TerminalRepr):
|
||||||
|
|
||||||
class DoctestItem(pytest.Item):
|
class DoctestItem(pytest.Item):
|
||||||
def repr_failure(self, excinfo):
|
def repr_failure(self, excinfo):
|
||||||
if excinfo.errisinstance(py.std.doctest.DocTestFailure):
|
doctest = py.std.doctest
|
||||||
|
if excinfo.errisinstance((doctest.DocTestFailure,
|
||||||
|
doctest.UnexpectedException)):
|
||||||
doctestfailure = excinfo.value
|
doctestfailure = excinfo.value
|
||||||
example = doctestfailure.example
|
example = doctestfailure.example
|
||||||
test = doctestfailure.test
|
test = doctestfailure.test
|
||||||
|
@ -50,12 +52,15 @@ class DoctestItem(pytest.Item):
|
||||||
for line in filelines[i:lineno]:
|
for line in filelines[i:lineno]:
|
||||||
lines.append("%03d %s" % (i+1, line))
|
lines.append("%03d %s" % (i+1, line))
|
||||||
i += 1
|
i += 1
|
||||||
lines += checker.output_difference(example,
|
if excinfo.errisinstance(doctest.DocTestFailure):
|
||||||
doctestfailure.got, REPORT_UDIFF).split("\n")
|
lines += checker.output_difference(example,
|
||||||
|
doctestfailure.got, REPORT_UDIFF).split("\n")
|
||||||
|
else:
|
||||||
|
inner_excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
|
||||||
|
lines += ["UNEXPECTED EXCEPTION: %s" %
|
||||||
|
repr(inner_excinfo.value)]
|
||||||
|
|
||||||
return ReprFailDoctest(reprlocation, lines)
|
return ReprFailDoctest(reprlocation, lines)
|
||||||
elif excinfo.errisinstance(py.std.doctest.UnexpectedException):
|
|
||||||
excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
|
|
||||||
return super(DoctestItem, self).repr_failure(excinfo)
|
|
||||||
else:
|
else:
|
||||||
return super(DoctestItem, self).repr_failure(excinfo)
|
return super(DoctestItem, self).repr_failure(excinfo)
|
||||||
|
|
||||||
|
|
|
@ -48,19 +48,16 @@ class TestDoctests:
|
||||||
def test_doctest_unexpected_exception(self, testdir):
|
def test_doctest_unexpected_exception(self, testdir):
|
||||||
p = testdir.maketxtfile("""
|
p = testdir.maketxtfile("""
|
||||||
>>> i = 0
|
>>> i = 0
|
||||||
>>> i = 1
|
>>> 0 / i
|
||||||
>>> x
|
|
||||||
2
|
2
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(p)
|
result = testdir.runpytest("--doctest-modules")
|
||||||
call = reprec.getcall("pytest_runtest_logreport")
|
result.stdout.fnmatch_lines([
|
||||||
assert call.report.failed
|
"*unexpected_exception*",
|
||||||
assert call.report.longrepr
|
"*>>> i = 0*",
|
||||||
# XXX
|
"*>>> 0 / i*",
|
||||||
#testitem, = items
|
"*UNEXPECTED*ZeroDivision*",
|
||||||
#excinfo = pytest.raises(Failed, "testitem.runtest()")
|
])
|
||||||
#repr = testitem.repr_failure(excinfo, ("", ""))
|
|
||||||
#assert repr.reprlocation
|
|
||||||
|
|
||||||
def test_doctestmodule(self, testdir):
|
def test_doctestmodule(self, testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue