-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Ignore other warnings when checking warnings #9527
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
Ignore other warnings when checking warnings #9527
Conversation
|
please review |
CodSpeed Performance ReportMerging #9527 will not alter performanceComparing Summary
|
a78313b to
266bac9
Compare
Building on Michał's amazing work in PR#9040, extend the pattern to also ignore other warnings that are emitted by pytest.warns() when running under Pytest 8.x. This also continues to support Pytest 7.x. Co-authored-by: Michał Górny <mgorny@gentoo.org> Fixes: pydantic#9025
266bac9 to
7fb3152
Compare
| os.environ['PYDANTIC_ERRORS_OMIT_URL'] = 'true' | ||
| os.environ['PYDANTIC_ERRORS_INCLUDE_URL'] = 'false' |
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 could potentially be a breaking change (though I'm not sure who might have this enabled?)
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.
Could it, in a conftest? Based on the commit message for that bit in #9040 this also to silence a warning.
|
@sydney-runkle Thanks for the linting fix, but no, this PR can be merged as-is -- it builds on the work done in #9040 so I wanted to make certain @mgorny was also credited for the work done. |
|
@s-t-e-v-e-n-k and @mgorny, Thanks for the awesome work here. One lingering question that I still have - for the case where we're catching multiple warnings, what about something like: import warnings
import pytest
def test_multiple_warnings():
with pytest.warns((UserWarning, RuntimeWarning)) as record:
warnings.warn("This is a user warning", UserWarning)
warnings.warn("This is a runtime warning", RuntimeWarning)
assert len(record) == 2 # check that two warnings were raised
assert isinstance(record[0].message, UserWarning) # check the type of the first warning
assert str(record[0].message) == "This is a user warning" # check the first warning message
assert isinstance(record[1].message, RuntimeWarning) # check the type of the second warning
assert str(record[1].message) == "This is a runtime warning" # check the second warning messageThe only thing that I feel is missing from the current implementation is details regarding the second, third, etc warnings being raised, which I think we want to preserve. |
|
I completely agree that would be an excellent change, and also allows us to know which code paths raise what warnings -- however, that change will also drop support for pytest 7.4 -- I'm happy to do so, but it would be a larger change. |
|
Ok, gotcha. This looks good then. I appreciate the TODO additions to have as a future reference! |
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.
Looks good, thanks for your work on this folks.
When do you guys think it makes sense to drop support for Pytest 7.4?
|
Thanks! |
Change Summary
Building on Michał's amazing work in #9040 , extend the pattern to also ignore other warnings that are emitted by pytest.warns() when running under Pytest 8.x. This also continues to support Pytest 7.x.
Co-authored-by: Michał Górny mgorny@gentoo.org
Related issue number
Fixes: #9025
Checklist
Selected Reviewer: @hramezani