-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Should pytest.warns check for issubclass rather than class equality? #2151
Comments
Documentation reads:
It isn't really clear how 'similar' this works since your example shows a clear difference. Not sure if the functionality should change (seems so, though?) but if it doesn't, then the documentation should be made clearer. |
I am kind of leaning this way too. Two additional data points outside of nose: stdlib warning filters import warnings
warnings.simplefilter('error', Warning)
warnings.warn('user', UserWarning) # warning turned into error nose assert_warnings import nose
with nose.tools.assert_warnings(Warning):
warnings.warn('user', UserWarning) # pass because UserWarning is a subclass of Warning |
@lesteve |
Since the other examples do match subclasses, I think it kind makes sense as well (specially with the similarity with
Agreed! |
Closed by #2166. |
pytest.warns
check for class equality and not subclass relationship. This snippet for example fails:This was slightly surprising to me since my expectation was that it would be similar to
pytest.raises
where you can check for a base class:What do you guys think? After all you can always use
with pytest.warns(None) as warninfo
and checkissubclass(warninfo[0].message, a_warning_class)
if you want to check a subclass relationship. At the same time, I don't really how it would hurt to check subclass relationship.I guess that is just a matter of changing this line by:
I am willing to open a PR about this if you think it is worth it.
The text was updated successfully, but these errors were encountered: