Skip to content
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

Easier way to check RuleBasedStateMachine invariants only when fully initialized #2868

Closed
Zac-HD opened this issue Feb 21, 2021 · 2 comments · Fixed by #2887
Closed

Easier way to check RuleBasedStateMachine invariants only when fully initialized #2868

Zac-HD opened this issue Feb 21, 2021 · 2 comments · Fixed by #2887
Assignees
Labels
enhancement it's not broken, but we want it to be better

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Feb 21, 2021

When using stateful testing, @invariant() methods are currently checked between every @initialize() method as well as between @rule() methods - which is awkward if your invariants require the machine to be initialized (see #2860 for discussion).

Instead of requiring users to use @precondition() decorators and track the "fully initialized" state themselves, I propose that we should add a new argument to the invariant decorator:

def invariant(*, check_before_initialized=True):

to make disabling this behaviour on a per-invariant basis more convenient.

Contra #2860, I think we should retain the existing (always check invariants) behaviour by default - our API style guide emphasises avoiding things that can lead to "unexpectedly weak tests". I'm open to suggestions for a better parameter name, with the goal that it should be very obvious than @invariant(argname=True) is checked both before and after while False is only checked after.

@Zalathar
Copy link
Contributor

Zalathar commented Feb 21, 2021

If anything I’m leaning the other way at the moment.

I’m struggling to imagine a realistic use case for checking invariants during partial init. Even in cases where it would be useful, we’d still check invariants after all initializers complete successfully, so the worst case is that we fail slightly later than we otherwise would have.

@Zac-HD Zac-HD self-assigned this Mar 1, 2021
@Zac-HD
Copy link
Member Author

Zac-HD commented Mar 1, 2021

After #2883 is merged, I'll open a PR for this issue from Zac-HD/hypothesis@multiple-preconditions...init-then-invariants.

This was referenced Mar 10, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants