-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
pytest warnings due to deprecation of pytest.warns(None) #22572
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
Comments
Thanks for opening the issue! Since To be specific: with pytest.warns(None) as record:
... can be directly replaced with: with warnings.catch_warnings(record=True) as record:
... |
Here is a list of files containing
I guess solving this issue will also move forward #22396. |
Hello - I'd like to help tackle this problem if that'd be alright? If someone else is already working on this please just let me know! |
Hello @ShanDeng123 |
I am curious if the issue is more complex than Find-Replace... And if |
I think it's better to do one PR per file. See #22572 (comment) for details. |
@avm19 @thomasjpfan That being said - would any of you guys know if this would necessitate an update to the changelog document? And if so, would the note be a bullet under the main Changelog header? |
It is not necessary to update the changelog, since it is not a public facing change. |
Coming from #22822 (comment) I think it's better to do this one per file. When we write the following to test for no warnings: with pytest.warns(None) as record:
...
assert not [w.message for w in record] I think the better solution is to replace that with: with warnings.catch_warnings():
warnings.simplefilter("error", EXPECTED_WARNING)
... where If we do not know the expected warning then we can write: with warnings.catch_warnings():
warnings.simplefilter("error")
... (But I prefer to have the expected warning) |
Will do - I'll go back over the files with 1 PR each, and look to add the extra detail when applicable 👍 |
I opened #22824 as a demonstration of what the idea looks like. Let's wait to see what other maintainers think before opening more. |
@ShanDeng123 #22824 has been merged. You may open a PR per file to address the other ones following the idea in #22572 (comment) . |
Working on sklearn/metrics/tests/test_classification.py |
@thomasjpfan Would it be fair to say that pytest.warns(None) generally checks for UserWarning unless the surrounding statements suggest otherwise? For example, in test_feature_agglomeration, I'd imagine that the expected warning is a UserWarning for the code below but I'd be lying if I said I had any confidence in that answer. |
The only way to check is through For that specific case, there is no deprecation warning anymore in the code, so I would remove the "no warnings" check all together. The PR should state the reason for removing the "no warning" check. |
Hey @thomasjpfan I'm a first-time contributor, could you please review my changes? Thank you so much. |
i can work on sklearn/tests/test_naive_bayes.py |
|
Reopening as some tests still need to be modified. |
@jeremiedbb this should be the last file having the outdated syntax, I've opened another PR to fix this issue. Could you please review it? |
Also #22949 is still open |
|
* Fixed tpf.interact() : lc plot ylabel, case normalized flux * Fixed tests compatibility with pytest v8 - patterned after: scikit-learn/scikit-learn#22572 (comment) * add to changelog [no ci]
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description This PR addresses errors produced by using `pytest.warns` with `None` args See [this failing action](https://github.com/argilla-io/argilla/actions/runs/7715020702/job/21028986681#step:12:23277), and [this thread](scikit-learn/scikit-learn#22572 (comment)) for more info. **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Refactor (change restructuring the codebase without changing functionality) - [X] Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** (Please describe the tests that you ran to verify your changes. And ideally, reference `tests`) - [ ] Test A - [ ] Test B **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/)
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description This PR addresses errors produced by using `pytest.warns` with `None` args See [this failing action](https://github.com/argilla-io/argilla/actions/runs/7715020702/job/21028986681#step:12:23277), and [this thread](scikit-learn/scikit-learn#22572 (comment)) for more info. **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Refactor (change restructuring the codebase without changing functionality) - [X] Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** (Please describe the tests that you ran to verify your changes. And ideally, reference `tests`) - [ ] Test A - [ ] Test B **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/)
Pytest issues warnings about using
pytest.warns(None)
context manager, where theNone
part is now being deprecated.For example,
>>> pytest ./sklearn/tests/test_naive_bayes.py
results in
79 passed, 4 warnings
. After commenting out--disable-pytest-warnings
key in[tool:pytest]
section ofsetup.cfg
, I could see that some of the warnings are:Apparently,
pytest.warns(None)
is deprecated for being widely misunderstood. I think that while sklearn's tests do not suffer from this misunderstanding, they might be affected in the future if and when pytest raises an error instead of a deprecation warning. (I couldn't figure out if this is planned for pytest's future releases, but in any case, avoiding the deprecation and reducing the warnings count won't harm.)I found this message , which is relevant to how
pytest.warns(None)
is used in scikit-learn tests, and how this could be changed. I opened this issue to share this information and quote the message, as it may save someone time in the future.The text was updated successfully, but these errors were encountered: