-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
deprecated_call context manager captures warnings already raised #2480
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
deprecated_call context manager captures warnings already raised #2480
Conversation
def f(): | ||
pass | ||
|
||
msg = 'Did not produce DeprecationWarning or PendingDeprecationWarning' |
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.
Now both context-manager form and function-call form produce the same message; note that previously the context-manager version produced a "DID NOT WARN..."
message from pytest.warns
instead (see the removed lines just above this one).
I think the vast majority of users just use pytest.deprecated_call
to ensure things are issuing deprecation warnings, not actually capturing the AssertionError and checking the message; the latter only makes sense when testing that pytest.deprecated_call
works and raises the expected message, which I think it is done only pytest's own test suite.
Having said that, do you feel because of this we should play safe and merge this into features instead?
_pytest/recwarn.py
Outdated
return WarningsChecker(expected_warning=(DeprecationWarning, PendingDeprecationWarning)) | ||
return _DeprecatedCallContext() | ||
else: | ||
with _DeprecatedCallContext(): |
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.
tracebackhide might be helpfull
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.
Good catch, thanks!
Fixed.
👍 |
This normalizes the context-manager and function form of
deprecated_call
by using the exact same implementation.I also updated the docs to mention the context-manager form first.
Fix #2469