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
Bypass small examples in stateful testing #3562
Comments
If possible, mind sharing the code being used? It might be the way the strategy is constructed for your test leads itself to generating uninteresting/repetitive examples. Also if you could share the terminal output when you run your tests with the flags
Have examples repeat can be useful, namely as it can catch bugs related to states, i.e. if you pass the same arg twice to a function and unexpectedly get different results. But yeah if it's a ton of repetition than something needs addressing. |
Unfortunately I cannot share the code as it's proprietary. To give a rough idea, the test setup consists of a process written in C++ and several test mocks that interface with the process via different protocols. The stateful tests communicate with the mocks to produce different test actions and read back outputs from the process. One thing I also noticed is that the search strategy used by RuleBasedStateMachine orders the rules based on their "complexity", i.e., number of inputs and preconditions etc. This ordering may also play role here, as the initial repetitions consist of the simplest rule that has no parameters and, therefore, does not produce any variations. I agree that some amount of repetition can be beneficial but seeing those same 50 cases every time makes one wonder it they could be skipped or at least reduced to just a few cases. Also running the 50 cases currently takes one to two minutes, so they are a bit painful to watch go by. |
Just to experiment, I changed the small_example_cap to zero in engine.py. This generated more interesting examples almost immediately. It would really be nice to have a way to control the small_example_cap from the Hypothesis API. |
The trouble is that I suspect that #3086 will also help, by improving our ability to detect redundant outputs. |
Thank you for the response. My suggestion was to allow control of small_example_cap, for example, by adding it to the settings. I will check #3086. |
We're pretty strongly against exposing such internals though the public API. It's a pretty nasty abstraction-violation which makes the library a lot harder to learn and use, and also holds back future development via compatbility constraints. |
Could you add a setting that would allow indirect control of the amount of small examples? Something like |
No, I will decline any PR adding such a setting. At minimum, every new setting adds to the size of our docs and makes Hypothesis slightly harder to understand (or be confident that you understand). Again, if you can create a non-sensitive test that demonstrates this issue I'm confident that some other mitigations are possible; including some which are already on the issue tracker. (though, as a volunteer-driven OSS project, not on a roadmap or timeline) |
I am using the stateful testing features of Hypothesis. I have the issue that Hypothesis always generates ~50 identical very simple test cases initially. These tests are not useful as they contain no variation.
I checked Hypothesis source code and found the "small_example_cap" in engine.py generate_new_examples() function, that seems to be responsible for these 50 cases. Its based on the "max_examples" setting, but it cannot be set directly.
It would be nice to be able to bypass and configure the amount of small examples in stateful tests.
The text was updated successfully, but these errors were encountered: