gh-111159: Fix SyntaxError doctests for non-builtin exception classes (#111541)

This commit is contained in:
Nikita Sobolev 2023-11-04 12:54:10 +03:00 committed by GitHub
parent a8e1f474c2
commit 18c954849b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -1399,10 +1399,14 @@ class DocTestRunner:
# 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)
exception_line_prefixes = (
f"{exception[0].__qualname__}:",
f"{exception[0].__module__}.{exception[0].__qualname__}:",
)
exc_msg_index = next(
index
for index, line in enumerate(formatted_ex)
if line.startswith(f"{exception[0].__name__}:")
if line.startswith(exception_line_prefixes)
)
formatted_ex = formatted_ex[exc_msg_index:]