what is the difference between seed and derandomize in python hypothesis testing framework?

34 views Asked by At

In stateful test, If I use a fixed seed and setting.derandomize(True or False) together, what is the behavior of the randomize?

what confuse me is the following scenarios:

when I use a fixed seed and settings.derandomize=False, I will get different result when I rerun the test.

but when I use a fixed seed and settings.derandomize=True, I can get the same result when I rerun the test.

I want to find out why I get different result on different runs in the first scenario。 but I don't know how to do.

1

There are 1 answers

0
Zac Hatfield-Dodds On

derandomize=True has two effects:

  1. Set a fixed seed based on a hash of the test function
  2. Disable the database, so we don't replay previously-found examples

The idea is that the @seed(...) decorator is meant to help you reproduce a failure which was e.g. found in CI, and so replaying old examples is probably helpful or at worst adds a bit of latency; whereas if you pass derandomize=True you actually want determinism.

You can read more about this in our docs. Fixed seeds can be convenient due to the command-line support via our Pytest plugin, but I'd generally avoid them otherwise in favor of the database and @reproduce_failure().