doctest: strip newlines with unexpected exceptions (#6801)
This commit is contained in:
parent
be23aeb989
commit
ac3a42bafd
|
@ -0,0 +1 @@
|
||||||
|
Do not display empty lines inbetween traceback for unexpected exceptions with doctests.
|
|
@ -313,7 +313,10 @@ class DoctestItem(pytest.Item):
|
||||||
else:
|
else:
|
||||||
inner_excinfo = ExceptionInfo(failure.exc_info)
|
inner_excinfo = ExceptionInfo(failure.exc_info)
|
||||||
lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
|
lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
|
||||||
lines += traceback.format_exception(*failure.exc_info)
|
lines += [
|
||||||
|
x.strip("\n")
|
||||||
|
for x in traceback.format_exception(*failure.exc_info)
|
||||||
|
]
|
||||||
reprlocation_lines.append((reprlocation, lines))
|
reprlocation_lines.append((reprlocation, lines))
|
||||||
return ReprFailDoctest(reprlocation_lines)
|
return ReprFailDoctest(reprlocation_lines)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -179,11 +179,21 @@ class TestDoctests:
|
||||||
result = testdir.runpytest("--doctest-modules")
|
result = testdir.runpytest("--doctest-modules")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"*unexpected_exception*",
|
"test_doctest_unexpected_exception.txt F *",
|
||||||
"*>>> i = 0*",
|
"",
|
||||||
"*>>> 0 / i*",
|
"*= FAILURES =*",
|
||||||
"*UNEXPECTED*ZeroDivision*",
|
"*_ [[]doctest[]] test_doctest_unexpected_exception.txt _*",
|
||||||
]
|
"001 >>> i = 0",
|
||||||
|
"002 >>> 0 / i",
|
||||||
|
"UNEXPECTED EXCEPTION: ZeroDivisionError*",
|
||||||
|
"Traceback (most recent call last):",
|
||||||
|
' File "*/doctest.py", line *, in __run',
|
||||||
|
" *",
|
||||||
|
' File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
|
||||||
|
"ZeroDivisionError: division by zero",
|
||||||
|
"*/test_doctest_unexpected_exception.txt:2: UnexpectedException",
|
||||||
|
],
|
||||||
|
consecutive=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_doctest_outcomes(self, testdir):
|
def test_doctest_outcomes(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue