-
-
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
pytest.warns
hides type errors in warnings.warn
calls
#10865
Comments
Hmm that's unfortunate, thanks for the report! Should be simple to fix. |
You're welcome! Certainly confused me for a minute :) I'm happy to contribute a fix — want to just raise a type error if it's not a string? Looks like CPython allows |
While trying to find the logic where this
but the
I feel like this caused me an error outside of pytest as well though |
Are you sure? This works for me: import warnings
def test_example_two():
warnings.warn(1) Which Python and pytest versions are you using? |
The Python and pytest versions are included in the original post, but consider me very confused — I did not reproduce this with the minimal example and a test matrix at https://github.com/madkinsz/pytest-10865/actions/runs/4714285419/jobs/8360551859 It does however reproduce quite clearly when I'm working in |
The issue appears to be related to import warnings
# Does not raise a type error
warnings.warn(1)
# Raises a type error
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "test")
warnings.warn(1) with the addition of a warnings filter to pytest zanieb/pytest-10865@1c3e4e3 the type error is raised on all Python and 7.x pytest versions https://github.com/madkinsz/pytest-10865/actions/runs/4714336351 |
I've opened a CPython issue as this doesn't really seem like pytest's fault python/cpython#103577 but pytest probably shouldn't hide this error still. |
@nicoddemus I don't expect there to be changes upstream for this. Should we validate that argument is of the correct type in pytest? |
as far as im concerned, type metadata in typeshed is provided, and my understandig is, that it would point to the error |
@RonnyPfannschmidt the problem here is that when using |
Retagging as bug based on upstream discussion, where consensus looks like "this should always error" and CPython may change accordingly. |
Hi, please review |
[ ] output ofpip list
from the virtual environment you are usingWhen using
pytest.warns
, incorrect values sent towarnings.warn
are not reported obscuring bugs:Related to #9288
The text was updated successfully, but these errors were encountered: