-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Make test ordering and parametrization reproducible #4788
Make test ordering and parametrization reproducible #4788
Conversation
Avoid order dependent on set or dict ordering.
Make it obey seeding with numpy.random.seed.
Seed random number generators when set to have reproducible pytest parameters some of which depend on random numbers. Adjust the check/pytest* scripts to set a zero seed by default.
Set reproducible, but non-constant default random seed for testing.
Some CI tests run in Python environment without numpy. Skip seeding of random number generator in such case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We can also use pytest-randomly to get random a seed but it will also come with other stuff; like running the tests in random order, so I'm fine with this. |
Oh, we can pass in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add export CIRQ_TESTING_RANDOM_SEED
to the incremental coverage checks as well.
The incremental-coverage scripts run tests with
Is there perhaps some other script that I am missing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay.
If you have the time to try pytest-randomly
, please do. In the conftest.py
, we can have
@pytest.fixture()
def global_seed(pytestconfig) -> int:
return pytestconfig.getoption("randomly_seed")
This will shave a lot of code in this PR with the caveat of us adding pytest-randomly
as a Dev tools dependency.
They have a wontfix issue pytest-dev/pytest-randomly#75 which implies that having random parameters in
Resetting random seed for every test case as done in pytest-randomly sounds fishy, because every test then gets the same handful of random numbers from the start of a seeded RNG sequence. On the other hand, the randomized test order with pytest-randomly sounds useful provided it indeed works with pytest-xdist. |
@vtomole - please let me know if there are still some changes required here. |
@pavoljuhas Thanks for the ping. I missed the first notification. I'll finish reviewing this today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Okay. Thanks for looking into it. |
Implement deterministic ordering of pytest parameters. Add CIRQ_TESTING_RANDOM_SEED environment variable for seeding random numbers generation in random and numpy.random modules. Use commit epoch time as the default seed to have a non-constant, but deterministic seeding. NB: Use empty CIRQ_TESTING_RANDOM_SEED to prevent seeding, for example, CIRQ_TESTING_RANDOM_SEED="" check/pytest This implements quantumlib#4787
- Require pytest-randomly for the testing to ensure RNG-generated test parameters are consistent across parallel test jobs. - Remove check/pytest option --actually-quiet which disables pytest-randomly hook for seeding parallel test jobs. - Remove `CIRQ_TESTING_RANDOM_SEED` as it is not needed anymore. - Remove RNG seeding in the tests where it seems redundant. - Clean up one instance of unnecessary test parametrization. This upholds #4787 and replaces #4788. Reverts #1825 and obsoletes #1826.
Implement deterministic ordering of pytest parameters. Add CIRQ_TESTING_RANDOM_SEED environment variable for seeding random numbers generation in random and numpy.random modules. Use commit epoch time as the default seed to have a non-constant, but deterministic seeding. NB: Use empty CIRQ_TESTING_RANDOM_SEED to prevent seeding, for example, CIRQ_TESTING_RANDOM_SEED="" check/pytest This implements quantumlib#4787
…ib#5868) - Require pytest-randomly for the testing to ensure RNG-generated test parameters are consistent across parallel test jobs. - Remove check/pytest option --actually-quiet which disables pytest-randomly hook for seeding parallel test jobs. - Remove `CIRQ_TESTING_RANDOM_SEED` as it is not needed anymore. - Remove RNG seeding in the tests where it seems redundant. - Clean up one instance of unnecessary test parametrization. This upholds quantumlib#4787 and replaces quantumlib#4788. Reverts quantumlib#1825 and obsoletes quantumlib#1826.
Implement deterministic ordering of pytest parameters. Add CIRQ_TESTING_RANDOM_SEED environment variable for seeding random numbers generation in random and numpy.random modules. Use commit epoch time as the default seed to have a non-constant, but deterministic seeding. NB: Use empty CIRQ_TESTING_RANDOM_SEED to prevent seeding, for example, CIRQ_TESTING_RANDOM_SEED="" check/pytest This implements quantumlib#4787
…ib#5868) - Require pytest-randomly for the testing to ensure RNG-generated test parameters are consistent across parallel test jobs. - Remove check/pytest option --actually-quiet which disables pytest-randomly hook for seeding parallel test jobs. - Remove `CIRQ_TESTING_RANDOM_SEED` as it is not needed anymore. - Remove RNG seeding in the tests where it seems redundant. - Clean up one instance of unnecessary test parametrization. This upholds quantumlib#4787 and replaces quantumlib#4788. Reverts quantumlib#1825 and obsoletes quantumlib#1826.
Implement deterministic ordering of pytest parameters.
Add CIRQ_TESTING_RANDOM_SEED environment variable for seeding
random numbers generation in random and numpy.random modules.
Use commit epoch time as the default seed to have a non-constant,
but deterministic seeding.
NB: Use empty CIRQ_TESTING_RANDOM_SEED to prevent seeding, for example,
CIRQ_TESTING_RANDOM_SEED="" check/pytest
This implements #4787