Reputation: 7020
If Python hypothesis strategies are too deeply nested, using draw
will not create an actual example, but a LazyStrategy
. This can be quite problematic at times because the resulting object behaves very differently from an actual example.
Is there a way to enforce eager evaluations of strategies, such that calling draw
always returns an actual example of the corresponding strategy?
For example:
from hypothesis import strategies as st
@st.composite
def my_composite_strategy(draw):
some_example = draw(some_very_complex_deeply_nested_strategy)
print(type(some_example))
...
Will print <class 'hypothesis.strategies._internal.lazy.LazyStrategy'>
if executed. What I want instead is <class 'my_module.MyObjectIWriteAStrategyFor'>
, so I can use some_example
really as if it was a real object.
Upvotes: 0
Views: 821
Reputation: 3003
As per https://github.com/HypothesisWorks/hypothesis/issues/3224, your some_very_complex_deeply_nested_strategy
is returning a strategy rather than the object you want
Upvotes: 2