3 ms·
Hypothesis also has two different ways to generate data: - One is to write things like in the article: accept data via arguments, and specify a strategy for ea
by chriswarbo 4y ago
Hypothesis also has two different ways to generate data:
- One is to write things like in the article: accept data via arguments, and specify a strategy for each up-front.
- Another is to be more ad-hoc: use the 'data' strategy to get a data generator which can be called on-the-fly at the point it's needed inside our test. This is useful if our test is complicated, e.g. with a bunch of conditional logic where each branch needs something different; or the data generation depends on some run-time values (e.g. the number of results we got from the database); etc. Hypothesis will still keep track of the random seeds, perform shrinking, etc. as usual.
The latter approach is described at https://hypothesis.readthedocs.io/en/latest/data.html#drawing-interactively-in-tests https://hypothesis.readthedocs.io/en/latest/data.html#drawin...