I am trying to generate dictionaries containing different python types as values using the hypothesis module.
For lists I can do this simply using the expression
from hypothesis import given
import hypothesis.strategies as st
@given(
st.lists(
st.from_type(type)
.flatmap(st.from_type)
.filter(lambda x: not isinstance(x, (type(None)))),
min_size=2,
unique_by=lambda x: type(x),
)
)
def test_something(dictionary):
...
which gives me [int, str, ...]
(different python type for each entry).
But for dictionaries, I there is no unique_by
for the values.
@given(
st.dictionaries(
st.text(min_size=1, max_size=10),
st.from_type(type).flatmap(st.from_type)
.filter(lambda x: not isinstance(x, (type(None), bool))),
min_size=2,
)
)
def test_something(dictionary):
...
which results in e.g. {'a': int, 'b': int, ...}
→ the type of value is the same for all entries.
Is there an easy way to generate {'a': int, 'b': str, ..}
(at least two different python types in dict.values()
)?