-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Deprecation warnings introduced in #10850 can't be filtered by pytest #11883
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
Increasing the stacklevel had some unintended side-effects, so this commit reverts that part. Closes numpy#11883
OK, confirmed. The stacklevel=2 warnings can be suppressed in |
Changing my mind, the |
Short rundown of the scenarios I tried: Setupenvironment dependencies: same as in the top post test.py: def test_warning_stacklevel_1():
from warnings import warn
warn('foo', DeprecationWarning)
def test_warning_stacklevel_2():
from warnings import warn
warn('bar', DeprecationWarning, stacklevel=2)
def test_umath_warning():
from sklearn.ensemble import weight_boosting Warning message when running
1) - no pytest.ini, suppress on command linerun command:
I'm pretty stumped by this result to be honest. I expected 2) - pytest.ini with explicit DeprecationWarning suppressionpytest.ini:
run command:
Same result as in 1). 3) - pytest.ini with global no-warnings settingpytest.ini:
run command: But using this setting is discouraged by the pytest docu unless you absolutely have to use it. 4) - decorating test functions to drop warnings, based on substring matchingtest.py: @pytest.mark.filterwarnings('ignore:foo')
def test_warning_stacklevel_1():
from warnings import warn
warn('foo', DeprecationWarning)
@pytest.mark.filterwarnings('ignore:bar')
def test_warning_stacklevel_2():
from warnings import warn
warn('bar', DeprecationWarning, stacklevel=2)
@pytest.mark.filterwarnings('ignore:numpy.core.umath_tests')
def test_umath_warning():
from sklearn.ensemble import weight_boosting run command:
Same as 1) and 2). I would say that 1), 2), and 4) would be valid workarounds. I took your comments to mean that these options do work for you, can you confirm that? If yes, something spooky might be afoot regarding environments. That being said, my gitlab CI, which runs on alpine, shows the same behavior as these scenarios here. So it's at least somewhat consistent. |
We just ran into a problem with pytest 3.8.0, released yesterday, and in the process of resolving the issue discovered that the pytest.ini file was read in after the command line, thus had precedence. There is a new pytest release out today that reverses that. |
Might want to escape the
although I don't think it will make a difference. |
I think it possible that sklearn is messing up the warnings stack, easy to do. We ended up rolling our own suppression filter and, IIRC, there was some comment about pytest not having it quite right at some time in the past, but possibly fixed (or not). EDIT: @seberg Thoughts? |
IIRC, the problem is that some (import) warnings are raised during pytest collection time and so it is not possible to filter them with a runtime filter, which I suspect the warnings filter is. |
@charris yeah, I don't think pytest tries to be as clean as numpy, but since this is python 3.7, I also do not think there should be any issue (plus the big issues we had is too little warning, not too many, basically why the pytest global filters are discouraged probably). I am a bit stumped as well... I mean all the warnings give the right line of code, etc. so the stacklevel seems completely fine (for a minute I thought maybe the level is just somewhere strange). Maybe we should ask pytest people? |
Tried to reproduce it by also having a module that calls a module that gives the warning and even I build the same import through numpy, and then decorated the numpy function with the ignore filter of another one, and the warning disappeared, if I ignore the correct one, it doesn't disappear, believe it or not, this weird thing runs without any warnings:
The rest of the setup is warnmod, its |
Do you know who'd be the right person to ping? Otherwise I'd just drop a fyi mail at [email protected] |
I think the problem arises because the |
Alright, I'll try to check every now and then whether this issue can be closed, then. From what you said, I understand that a stacklevel of 2 is the right way to handle this in numpy and shouldn't change, right? On another note, I found a different workaround for this issue that for some reason hadn't occurred to me before: import warnings
def test_umath_warning():
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
from sklearn.ensemble import weight_boosting This is what I'm currently doing. |
@a-recknagel Does latest pytest (3.10, released 20 hrs ago) fix this for you? |
@charris I can confirm that, at least in the latest pytest==3.10, with numpy/scikit/sklearn versions staying the same, the warning doesn't turn up any more if use the |
Uh oh!
There was an error while loading. Please reload this page.
A number of deprecation warnings were introduced with #10850 that can not be suppressed by pytest's warnings-capture options and will clutter the output.
I ran into the issue because sklearn still uses the deprecated functions, so I can't fix the issue in my own code. My repro-example will feature sklearn, but it shouldn't be necessary to isolate the issue.
Reproducing code example:
environment: python3.7.0, numpy==1.15.1, pytest==3.7.4, scikit-learn==0.19.2, scipy==1.1.0
Files: test.py
Run from command line:
Error message:
Possible fix:
Changing the stacklevel of all warnings from #10850 to 1 (i.e. the default value) solves the problem on my end.
The text was updated successfully, but these errors were encountered: