mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-111159: Fix doctest
output comparison for exceptions with notes (GH-111160) (#111169)
gh-111159: Fix `doctest` output comparison for exceptions with notes (GH-111160)
(cherry picked from commit fd60549c0a
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
1ea93024d4
commit
f6cde99bdb
3 changed files with 159 additions and 1 deletions
|
@ -1376,7 +1376,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