PR #1056 modified the pytest configuration to set a global random number seed, to deal with flaky tests that failed sporadically because some numerical comparisons exceeded tolerances undpredictably. Setting a global seed is not good practice. The seeds for test scenarios should be revised:
-
Avoid global seeds. It's generally better to avoid setting a global seed for all tests. Global seeds can cause unexpected behavior when different parts of the code rely on random numbers.
-
Use numpy.random.default_rng. It's considered better to create a Generator instance with a seed at the beginning of each test or test suite. This ensures that each test has its own independent random state.
-
Pass Generator objects. Pass the Generator object around as an argument. This makes the random number generation explicit and avoids relying on global state.
PR #1056 modified the pytest configuration to set a global random number seed, to deal with flaky tests that failed sporadically because some numerical comparisons exceeded tolerances undpredictably. Setting a global seed is not good practice. The seeds for test scenarios should be revised:
Avoid global seeds. It's generally better to avoid setting a global seed for all tests. Global seeds can cause unexpected behavior when different parts of the code rely on random numbers.
Use
numpy.random.default_rng. It's considered better to create aGeneratorinstance with a seed at the beginning of each test or test suite. This ensures that each test has its own independent random state.Pass
Generatorobjects. Pass theGeneratorobject around as an argument. This makes the random number generation explicit and avoids relying on global state.