-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stateful testing #1370
Comments
You're doing well! I assume you found the docs, but here's a link just in case 😄
|
Thanks for the help! class StatefulTestExample(RuleBasedStateMachine):
@initialize(obj=my_strategy)
def setup(self, obj):
self.obj = obj
@rule()
def step(self):
project.function(self.obj)
@rule()
def step2(self):
project.function2(self.obj)
@invariant()
def write_read_cycle(self):
if not hasattr(self, obj):
# Apparently the invariant is checked *before* running setup
return
out = serialize(self.obj)
found = deserialize(self.obj)
assert out == found
TestFoo = StatefulTestExample.TestCase However if I then run Edit: Scratch that, I just missed it. |
Can you share the exact output from pytest? It should show where the error arose. |
I just completely overlooked it. |
Hi all,
first off, thanks for making hypothesis, I've been using it only briefly now and I really like it so far.
I need a hand in setting up stateful testing, since it sound like The Right Thing To Do(c).
I have code that can serialize and deserialize certain objects, and I made a composite strategy to create these objects. In addition, I have some operations that I can perform on these objects as functions. What I want to do now is set up a stateful testing framework where 1) one of these objects is instantiated using my strategy, 2) 0 or more operations are performed on this objects, and 3) between all those steps an invariant is asserted. It would be awesome if I could also give different arguments to those functions in 2.
Unfortunately, I'm lost on how to do this. Here's my attempt so far, can someone give me a nudge in the right direction?
The text was updated successfully, but these errors were encountered: