Skip to content

Remove global random seed used for testing #1060

Description

@mhucka

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions