-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest.warns
multiple argument handling
#11917
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
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 regression with :func:`pytest.warns` using custom warning subclasses which have more than one parameter in their `__init__`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,10 +322,10 @@ def found_str(): | |
for w in self: | ||
if not self.matches(w): | ||
warnings.warn_explicit( | ||
str(w.message), | ||
w.message.__class__, # type: ignore[arg-type] | ||
w.filename, | ||
w.lineno, | ||
message=w.message, | ||
category=w.category, | ||
filename=w.filename, | ||
lineno=w.lineno, | ||
module=w.__module__, | ||
source=w.source, | ||
) | ||
|
@@ -336,7 +336,9 @@ def found_str(): | |
|
||
@staticmethod | ||
def _validate_message(wrn: Any) -> None: | ||
if not isinstance(msg := wrn.message.args[0], str): | ||
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. Can you explain these changes? 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. After making the other changes, the code failed some tests from #11804 that solved #10865, where the incorrect arguments then defaulted to becoming 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. Hm, this looks like it could be its own PR potentially. Another implementation: #11959 |
||
if type(wrn.message) is UserWarning and not isinstance( | ||
msg := wrn.message.args[0], str | ||
): | ||
raise TypeError( | ||
f"Warning message must be str, got {msg!r} (type {type(msg).__name__})" | ||
) |
Uh oh!
There was an error while loading. Please reload this page.