mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-111159: Fix doctest
output comparison for exceptions with notes (#111160)
This commit is contained in:
parent
5e7727b052
commit
fd60549c0a
3 changed files with 159 additions and 1 deletions
|
@ -1393,7 +1393,20 @@ class DocTestRunner:
|
|||
|
||||
# The example raised an exception: check if it was expected.
|
||||
else:
|
||||
exc_msg = traceback.format_exception_only(*exception[:2])[-1]
|
||||
formatted_ex = traceback.format_exception_only(*exception[:2])
|
||||
if issubclass(exception[0], SyntaxError):
|
||||
# SyntaxError / IndentationError is special:
|
||||
# we don't care about the carets / suggestions / etc
|
||||
# We only care about the error message and notes.
|
||||
# They start with `SyntaxError:` (or any other class name)
|
||||
exc_msg_index = next(
|
||||
index
|
||||
for index, line in enumerate(formatted_ex)
|
||||
if line.startswith(f"{exception[0].__name__}:")
|
||||
)
|
||||
formatted_ex = formatted_ex[exc_msg_index:]
|
||||
|
||||
exc_msg = "".join(formatted_ex)
|
||||
if not quiet:
|
||||
got += _exception_traceback(exception)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue