pytest warnings due to deprecation of pytest.warns(None)
See original GitHub issuePytest issues warnings about using pytest.warns(None)
context manager, where the None
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 of setup.cfg
, I could see that some of the warnings are:
PytestRemovedIn8Warning: Passing None has been deprecated. See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for alternatives in common use cases.
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 tests were of the form:
with pytest.warns(None) as record: <do some stuff> <check record for warnings, and possibly raise an error>
The tests were not assuming that the pytest context code would raise an error if a warning occurred. Instead, these tests were doing their own error checking based on
record
. So they were really usingpytest.warns(None)
exactly likewarnings.catch_warnings(record=True)
. (There is a pull request to make the change tocatch_warnings
.)
Issue Analytics
- State:
- Created 2 years ago
- Comments:35 (35 by maintainers)
Top GitHub Comments
Reopening as some tests still need to be modified.
@adamgonzo I’m working on the utils folder. However, feel free to work on that file