I am doing something roughly like this:
test_a.py
import unittest
import hypothesis
import hypothesis.extra.numpy
import numpy as np
from hypothesis import strategies as st
SHAPE = (10, )
ARRAY_STRATEGY = hypothesis.extra.numpy.arrays(float, SHAPE, elements=st.floats(min_value=-1, max_value=1))
ZERO_ONE_STRATEGY = st.floats(min_value=0, max_value=1)
class TestMyClass(unittest.TestCase):
@hypothesis.settings(max_examples=10)
@hypothesis.given(
value=ZERO_ONE_STRATEGY,
arr1=ARRAY_STRATEGY,
arr2=ARRAY_STRATEGY,
arr3=ARRAY_STRATEGY,
)
def test_something(self, value: float, arr1: np.ndarray, arr2: np.ndarray, arr3: np.ndarray) -> None:
print(value)
And I am often seeing behavior like this:
$ pytest test_a.py --capture=no
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
I am testing behavior with respect to value
, so sampling 0.0
10 times renders this test useless to me. I don't need to randomly sample value
, in fact, I would like to sample it evenly over the range of ZERO_ONE_STRATEGY
at the granularity of 1 / (max_examples - 1)
. How can I create a strategy to do that?