-
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
Document (or fix) limitations of stateful testing #1300
Comments
I find bundles to be endlessly confusing, and would Other than that, the inconsistencies you note above, and a trivial sense that I would have named things differently, it's not bad! The structure of a class with methods makes sense, and while I would probably use a class decorator (ala Attrs) to transform it and put a test in the global namespace IIRC that's hard to do compatibly. Uh, that's a "hate your tools" rant, but I actually do quite like stateful testing despite seeing the flaws. ❤️ |
I think that's more evidence that they need better documentation, because instance variables and the data strategy don't come close to replacing their functionality! |
(But I agree that most places where you can replace a bundle with an instance variable, you probably should) |
This is a minor limitation, but MWE: import pytest
from hypothesis import stateful
from hypothesis.strategies import booleans
class PytestMachine(stateful.RuleBasedStateMachine):
@stateful.rule(i=booleans())
@pytest.mark.parametrize('hi', (1, 2, 3))
def parametrize_after_rule(self, hi, i):
pass
TestPytestMachine = PytestMachine.TestCase Failure:
|
Some notes on rule-based stateful API friendliness, prompted by #1370:
|
We would also like to provide the parts required to implement stateful testing downstream as public API, for use by e.g. async libraries. See #1371 for a proof-of-concept of how this might work. Technically speaking you can just inherit from |
Regarding async stateful testing, @Zac-HD wrote over here, on @touilleMan's PR:
I'm replying here so my comment doesn't get lost on a random closed PR :-). There are a lot of sources of possible non-determinism in your average Trio program (or any other program that uses concurrency or I/O). Providing ways to control this for testing is really important, which is why Trio provides things like a deterministic clock and deterministic "network connections". I'd love to have Hypothesis strategies like "a network connection with random chunking and delays", or "scheduler that randomly reassigned priorities to catch race conditions". However, I think all this is mostly orthogonal to stateful testing? All of these things are useful/necessary with regular |
I agree on all counts - including both usefulness and orthogonality to stateful testing - but the implementation and more detailed discussion of that really belongs on a Trio issue tracker. (Personally I'd consider having an optional dependency on Hypothesis within |
@Zac-HD @njsmith so what would be the next step now ? I'm thinking to divide my previous POC into two PRs:
|
I don't think we (collectively) have enough experience with this kind of testing to write a useful API on the first attempt, so I'm feeling very cautious about adding something that would have to be supported for a long time. Instead, I'd rework your proof-of-concept into a standalone library I'll be basically unavailable for the next week, but keen to be involved once my schedule calms down a little. |
@Zac-HD @njsmith I've created the hypothesis-trio project with my POC in it. Currently there is a monkey patch of Anyway, the good news is from now on we have hypothesis stateful working with trio \o/ |
Because stateful testing is currently built on find, it had a number of features supported by
@given
that do not work. These include:Currently this isn't documented anywhere. We should document this at a minimum, though better yet would be rebuilding stateful testing and given to have more of a common mechanism.
The text was updated successfully, but these errors were encountered: