Skip to content

Commit

Permalink
avoid FailedHealthCheck in test_double
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Ben-Yehuda committed Jan 29, 2025
1 parent f89b5f7 commit fb68e6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/4879.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* fixed spurious `test_double` failures.
9 changes: 7 additions & 2 deletions pytests/tests/test_othermod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

from pyo3_pytests import othermod

INTEGER32_ST = st.integers(min_value=(-(2**31)), max_value=(2**31 - 1))
INTEGER31_ST = st.integers(min_value=(-(2**30)), max_value=(2**30 - 1))
USIZE_ST = st.integers(min_value=othermod.USIZE_MIN, max_value=othermod.USIZE_MAX)


@given(x=INTEGER32_ST)
# If the full 32 bits are used here, then you can get failures that look like this:
# hypothesis.errors.FailedHealthCheck: It looks like your strategy is filtering out a lot of data.
# Health check found 50 filtered examples but only 7 good ones.
#
# Limit the range to 31 bits to avoid this problem.
@given(x=INTEGER31_ST)
def test_double(x):
expected = x * 2
assume(-(2**31) <= expected <= (2**31 - 1))
Expand Down

0 comments on commit fb68e6e

Please sign in to comment.