There are a couple of ways to generate inter-dependent data, of which I'd usually recommend reaching for @st.composite
strategies - the imperative approach is a bit more verbose, but easy to read and works even for really complicated situations. Here:
@st.composite
def a_instances(draw):
ages = draw(st.dictionaries(st.text(), st.floats()))
names = list(ages) # could add elements, shuffle, etc here too.
return A(names=names, ages=ages)
Or we could exploit the simplicity of the A
class, and use a simpler but harder-to-extend strategy like:
a_instances = st.dictionaries(st.text(), st.floats()).map(
lambda ages: A(names=list(ages), ages=ages
)
As Samwise notes though, this is a pretty strange example and I'd personally try tidying up the code a bit then using @st.composite
.