Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shannoncai
Copy link

@shannoncai shannoncai commented Dec 7, 2024

Handles #12417

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 7, 2024
Copy link
Member

@nicoddemus nicoddemus left a 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"\.\.\.", ".*")
Copy link
Member

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.

Comment on lines +654 to +655
print(f"Transformed WANT: {want_regex}") # Debugging output
print(f"GOT: {got}") # Debugging output
Copy link
Member

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.

Suggested change
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _test_doctest_wildcard():
def doctest_wildcard():

@@ -0,0 +1 @@
Fix handling of ellipsis (...) in traceback comparisons for doctests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix handling of ellipsis (...) in traceback comparisons for doctests
Fix handling of ellipsis (``...``) in traceback comparisons for doctests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants