-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix handling of ellipsis (...) in traceback comparisons for doctests | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -649,6 +649,13 @@ | |||||
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 commentThe 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 Perhaps we can limit our replacement to lines containing a single 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 | ||||||
Comment on lines
+654
to
+655
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like those are left-overs.
Suggested change
|
||||||
if re.fullmatch(want_regex, got, re.DOTALL): | ||||||
return True | ||||||
|
||||||
return super().check_output(want, got, optionflags) | ||||||
|
||||||
def _remove_unwanted_precision(self, want: str, got: str) -> str: | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
Test that doctests with wildcards in tracebacks are handled correctly. | ||||||
""" | ||||||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
''' | ||||||
>>> _test_doctest_wildcard() | ||||||
Traceback (most recent call last): | ||||||
... | ||||||
ValueError: An error occurred | ||||||
''' | ||||||
raise ValueError("An error occurred") | ||||||
""" | ||||||
) | ||||||
|
||||||
# Run pytest with doctest support enabled. | ||||||
result = pytester.runpytest("--doctest-modules") | ||||||
|
||||||
# Check that the test passed without failures. | ||||||
result.assert_outcomes(passed=1, failed=0) |
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.