-
Notifications
You must be signed in to change notification settings - Fork 586
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
Set appropriate stacklevel= in all calls to warnings.warn()
#3403
Comments
|
👋 I'm going to attempt this one. |
|
I've created the following minimal, reproducible example for this. summary of versions (click me)Given a file from hypothesis import (
example,
given,
strategies as st
)
def _bad_max(x, y):
if x == 2:
return -1
else:
return max(x, y)
@given(st.integers(), st.integers())
@example(2, st.integers().example())
def test_max_works(x, y):
assert _bad_max(x, y) == max(x, y)Running this with all of pytest ./test_warnings.pyReturns a non-0 exit code as expected, and produces output that shows user code. But using warnings-as-errors, Hypothesis's warning is printed instead. pytest -Werror ./test_warnings.pyReturns a non-0 exit code, and points to a line in the user's test file, but doesn't show the test name. |
|
Nice! I think an even simpler repro for that warning would be: from hypothesis import strategies as st
def test():
st.integers().example()(in your MRE, the call to |
|
Cool, cool ok. So I think that both in my example (error at test collection time) and your example (error raised directly in the test codde), You get a line in the traceback pointing to the specific test file + line in that test file which caused the warning. Running your example with That seems pretty good to me. Can you help me understand what type of output you'd expect to see instead? I might be misunderstanding what "point to user code" means. |
|
Ok we talked about this in person. The issue is not about the behavior with warnings-as-errors, but in other settings where For example: """test_warnings.py"""
from hypothesis import strategies as st
def test():
st.integers().example()And running like this pytest -Wdefault ./test_warnings.pyYou'll currently get output that points to the line in Instead, we'd like to have the line point to user code, e.g. |
|
Using git grep -E 'warn\('Here's the complete list:
|
|
I manually checked each of these while writing the list at the top of the issue 😁 |
|
@Zac-HD I don't believe setting a single For example, given the following: from hypothesis import given, example, strategies as st
from hypothesis.configuration import set_hypothesis_home_dir
# mkdir -p /tmp/some-nonsense
# chmod 'a=r' /tmp/some-nonsense/
set_hypothesis_home_dir("/tmp/some-nonsense")
@given(st.text())
@example("a")
def test_search_strategy_warnings(x):
passRunning pytest -Wdefault ./test_database.pyI see the following with a hard-coded That image suggests that for this minimal case, Which of these would you prefer to see?
|
|
If it turns out to be variable, let's just ignore it for this issue 👍 |


I noticed in this lovely video that the warning for
st.integers().example()pointed into the Hypothesis internals, rather than at the calling user code. The solution is to setstacklevel=in:SearchStrategy.example()instrategies.pywarn_on_missing_dtypes()inarray_api.py- this might need to accept a newstacklevel=argument, since it's called from multiple different places. [turns out not to be worth the trouble 😞]Test plan: manually check that these warnings now point to user code - the problem isn't that we break such handling but rather that we hadn't added it in the first place.
The text was updated successfully, but these errors were encountered: