Stateful value generation

6 views
Skip to first unread message

Ben Sless

unread,
Jul 7, 2025, 10:04:31 AMJul 7
to Hypothesis users
Hey all,
I started using Hypothesis recently, have experience with PBT in other languages.
I've been trying to make a certain behavior work implementing a RuleBasedStateMachine:
Create an object in init that will have accountsm, e.g. self.obj = cls(...)
Have a rule for registering an account
Have another rule that can only perform on accounts that meet a certain condition.
What I would have wanted was to create a composite strategy that can accept self.obj, but I find no way to pass it in.
Additionally, even if I were to use a precondition to filter only for accounts that meet my requirement, how do I select from them correctly (such that narrowing and reproduction will work) in my rule?
I've read the documentation and examples, haven't been able to find a solution to this problem. Am I missing something or is it not possible the way Hypothesis works?

Thanks,
Ben

Ben Sless

unread,
Jul 7, 2025, 10:12:06 AMJul 7
to Hypothesis users
Answering my own question:
Should have used st.data() as an argument to the method which allowed me to pass arguments from self into the composite strategy and draw with it.
using st.data allows mixing test code and composite strategies.

Reply all
Reply to author
Forward
0 new messages