doctest: strip newlines with unexpected exceptions (#6801)

This commit is contained in:
Daniel Hahler 2020-02-24 15:18:08 +01:00 committed by GitHub
parent be23aeb989
commit ac3a42bafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 6 deletions

View File

@ -0,0 +1 @@
Do not display empty lines inbetween traceback for unexpected exceptions with doctests.

View File

@ -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:

View File

@ -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):