-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling of ellipsis in traceback comparisons for doctests #13039
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @shannoncai! Please take a look at the comments.
@@ -649,6 +649,13 @@ def remove_prefixes(regex: re.Pattern[str], txt: str) -> str: | |||
if allow_number: | |||
got = self._remove_unwanted_precision(want, got) | |||
|
|||
if "..." in want: | |||
want_regex = re.escape(want).replace(r"\.\.\.", ".*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit simplistic in the sense that it will replace any ...
found in the docstring, even if they are used in places where we don't want this replacement to happen, say inside a string literal.
Perhaps we can limit our replacement to lines containing a single ...
(minus spaces)?
Here is how the stdlib does this: https://github.com/python/cpython/blob/1503fc8f88d4903e61f76a78a30bcd581b0ee0cd/Lib/doctest.py#L295-L342
I'm OK with copying that code over pytest.
print(f"Transformed WANT: {want_regex}") # Debugging output | ||
print(f"GOT: {got}") # Debugging output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like those are left-overs.
print(f"Transformed WANT: {want_regex}") # Debugging output | |
print(f"GOT: {got}") # Debugging output |
@@ -1642,3 +1642,28 @@ def test_is_setup_py_different_encoding(tmp_path: Path, mod: str) -> None: | |||
def test_is_main_py(tmp_path: Path, name: str, expected: bool) -> None: | |||
dunder_main = tmp_path.joinpath(name) | |||
assert _is_main_py(dunder_main) == expected | |||
|
|||
|
|||
def test_doctest_wildcard(pytester): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_doctest_wildcard(pytester): | |
def test_doctest_wildcard(pytester: Pytester) -> None: |
# Create a Python file with a function that raises a ValueError and includes a doctest. | ||
pytester.makepyfile( | ||
""" | ||
def _test_doctest_wildcard(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _test_doctest_wildcard(): | |
def doctest_wildcard(): |
@@ -0,0 +1 @@ | |||
Fix handling of ellipsis (...) in traceback comparisons for doctests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix handling of ellipsis (...) in traceback comparisons for doctests | |
Fix handling of ellipsis (``...``) in traceback comparisons for doctests. |
Handles #12417