-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Inconsistent behavior of pytest.deprecated_call() #1190
Comments
Also wanted to share an extended example: import warnings
import pytest
def deprecated_function():
warnings.warn("deprecated", DeprecationWarning)
def test_one():
pass
def test_two():
pytest.deprecated_call(deprecated_function)
def test_three():
pytest.deprecated_call(deprecated_function)
def test_four():
deprecated_function()
def test_five():
pytest.deprecated_call(deprecated_function) This example fails with the same error around |
Thanks for the report @netme! |
Note: this fails only on Python 2.7. |
@nicoddemus Thanks for checking it. Yes, forgot to mention. Our product is using Python 2.7.8 . |
Temporary fixed it using warnings.simplefilter('always', DeprecationWarning) call close to our fixtures definition. |
Hmm that's strange. In #897 The following fails (note that import warnings
def deprecated_function():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings(record=True) as ws:
deprecated_function()
assert len(ws) == 1 If you change
Anybody with more knowledge of the |
I think the new behaviour makes sense, because ultimately, you want to test what the user will be seeing, right? If a user looks at your test, and sees that If we do decide to keep the new behaviour, we should definitely make sure it's documented in the changelog. Alternatively, we can revert to the old behaviour. The way I would do this is by removing filters for |
For interest, here's the reasoning on why |
in my oppinion py.test should always reenable all warnings @hpk42, @nicoddemus what do you think? |
Thanks a lot @hunse for the clear explanation. 😄 |
I think we should revert it: IMO keeping the current behavior would just lead to confusion, as users would see it fail all the time, unless they explicitly reset the filters themselves; seems like a poor user experience to me.
Personally I don't use warnings much so I don't have a strong opinion on this, but following what the If we agree to this, I think we should re-enable all warnings by default in |
Created a separate issue to discuss re-enabling all warnings. 😄 |
If @hpk42 agrees, I'd even go for it in the 2.8 series |
To re-enable all warnings? I'm not sure, seems like a big behavior change to me that should go into a minor release only, not in a bug fix release. |
well, its a clear regression from 2.7 so i think a fix in 2.8.x is acceptable |
Oh I see what you mean. IMO we have two issues, which are related, but can be treated separately:
|
good thinking, lets fix 1 with this issue and have an extra issue for 2 |
Agreed. 2 is already covered in #1191. 😄 |
Wait, this is nothing to do with |
I have code in EDIT: maybe because when the first warning is raised, none of the filters are set, so it gets added to some "ignore" list somewhere. Then, when the second warning is raised, the "always" filters are set, but it's already on that list, and gets ignored right away. I'm just guessing here. This needs more looking at, which unfortunately I don't have time for right now, but maybe I'll be able to get back to it tomorrow. |
I noticed that as well, forgot to mention it. Perhaps there is some internal state of |
@nicoddemus as far as I remember the problem is not around If you look on my example, the Hope that will help you with debugging. |
I think I figured it out. In this line you can see the registry being setup. If you look at up at that function, you can see that it tries to get the module to put the Then in this line we can see that it will just bail out and not issue a warning because the registry already contains an entry for I don't think there's much we can do other than revert the implementation of At least it is good to know what is actually happening here. 😅 I will prepare a PR restoring the |
similar to what we had in 2.7, with a few enhancements Fix pytest-dev#1190
similar to what we had in 2.7, with a few enhancements Fix pytest-dev#1190
similar to what we had in 2.7, with a few enhancements Fix pytest-dev#1190
Make deprecated_call() use monkey-patching again , fixes #1190
We are currently upgrading
py.test
from 2.7.1 to 2.8.3 . We have found a small inconsistency inpytest.deprecated_call()
behaviour.We have few tests which are calling deprecated methods in our codebase. And afterwards we have few tests which are checking that the methods are deprecated. Running that tests on 2.7.1 produce no issues. After switching to 2.8.3, we have found out that the tests which are using
pytest.deprecated_call()
started failing. Here is an example:When running it on 2.8.3, the following
AssertionError
is raised:On 2.7.1 it works fine.
Seems to be adding
warnings.simplefilter('always')
call beforedeprecated_function()
call fixes the issue:Could you please check this small issue?
The text was updated successfully, but these errors were encountered: