I started using hypothesis to write my tests. I like it, but I am stuck to generate some kind of data.
I have a test that use list of data, which can be constructed from tuple(key, value).
Key can be text, integer or float, value can be anything comparable. For one test, all keys must be the same type, and all values must be the same type.
The only way I found to generate data I want is something like that:
@given(
st.one_of(
st.lists(st.tuples(st.integers(), st.integers())),
st.lists(st.tuples(st.integers(), st.floats())),
st.lists(st.tuples(st.integers(), st.text())),
st.lists(st.tuples(st.floats(), st.integers())),
st.lists(st.tuples(st.floats(), st.floats())),
st.lists(st.tuples(st.floats(), st.text())),
#...
))
def test_stuff(lst):
data = [Mydata(k, v) for k, v in lst]
#...
Is there a better way to generate all data type combination I want to test ?