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:
|
||||
inner_excinfo = ExceptionInfo(failure.exc_info)
|
||||
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))
|
||||
return ReprFailDoctest(reprlocation_lines)
|
||||
else:
|
||||
|
|
|
@ -179,11 +179,21 @@ class TestDoctests:
|
|||
result = testdir.runpytest("--doctest-modules")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*unexpected_exception*",
|
||||
"*>>> i = 0*",
|
||||
"*>>> 0 / i*",
|
||||
"*UNEXPECTED*ZeroDivision*",
|
||||
]
|
||||
"test_doctest_unexpected_exception.txt F *",
|
||||
"",
|
||||
"*= FAILURES =*",
|
||||
"*_ [[]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):
|
||||
|
|
Loading…
Reference in New Issue