You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
can be made to fail by modifying the src-string to be:
SHOULD_NOT_IMPORT_NUMPY = """
import sys
from hypothesis import given, strategies as st
@given(st.integers() | st.floats() | st.sampled_from(["a", "b"]) | st.just(st.register_type_strategy(int, st.integers())))
def test_no_numpy_import(x):
assert "numpy" not in sys.modules
"""
This was causing a headache for me when figuring out why numpy was being imported the instant I ran pytest... this was because I happened to have installed numpy + hypothesis + pydantic (which uses st.register_type_strategy via our entrypoint).
This could be a big headache for testers over at, say, PyTorch, who want to test that they don't cause numpy to be imported.
The text was updated successfully, but these errors were encountered:
If I expected this to require a nasty patch - i.e. worse than our numpy special case in register_random - I wouldn't consider it worth fixing.
That's because once we make our pytest plugin lazily load Hypothesis (#3140), this will only trigger if you deliberately import hypothesisand somehow call st.register_type_strategy()in the test that Numpy is not imported, which usually happens in a fresh process.
Other libraries will never get this special treatment, but Numpy is already exceptional in our code and the ecosystem.
This is the "offending" block:
hypothesis/hypothesis-python/src/hypothesis/strategies/_internal/types.py
Lines 493 to 501 in 65b4b21
This test
hypothesis/hypothesis-python/tests/numpy/test_import.py
Lines 16 to 29 in 65b4b21
can be made to fail by modifying the src-string to be:
This was causing a headache for me when figuring out why numpy was being imported the instant I ran pytest... this was because I happened to have installed numpy + hypothesis + pydantic (which uses
st.register_type_strategy
via our entrypoint).This could be a big headache for testers over at, say, PyTorch, who want to test that they don't cause numpy to be imported.
The text was updated successfully, but these errors were encountered: