Skip to content
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

libregrtest should always set random.seed #110171

Closed
sobolevn opened this issue Oct 1, 2023 · 5 comments
Closed

libregrtest should always set random.seed #110171

sobolevn opened this issue Oct 1, 2023 · 5 comments
Assignees
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 1, 2023

Feature or enhancement

While working on #110160 I've noticed that it is rather hard to reproduce random test failures. So, I want to propose a new feature / fix for that.

First of all, there's existing prior work of @vstinner who added --randseed flag.
Right now it is used together with -r to randomize test order and seeding random.

I propose to:

  • Split --randseed into two options: test order randomization and random.seed usage
  • Let's keep -r as-is
  • Let's add --no-use-randseed flag to disable setting random.seed, let's always seed random by default
  • Always print information about current random seed to be able to reuse it in the next runs

Example:

» ./python.exe -m test test_regrtest
Using random seed 65906482
0:00:00 load avg: 1.55 Run 1 test sequentially
0:00:00 load avg: 1.55 [1/1] test_regrtest

== Tests result: SUCCESS ==

1 test OK.

Total duration: 12.7 sec
Total tests: run=102 skipped=2
Total test files: run=1/1
Result: SUCCESS

Basically, this is how https://github.com/pytest-dev/pytest-randomly works.

I have a PR ready.

Linked PRs

@sobolevn sobolevn added type-feature A feature request or enhancement tests Tests in the Lib/test dir labels Oct 1, 2023
@sobolevn sobolevn self-assigned this Oct 1, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 1, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 1, 2023
@terryjreedy
Copy link
Member

I think that the seed should be random but recorded so that a run can be reproduced.

@sobolevn
Copy link
Member Author

sobolevn commented Oct 1, 2023

Yes 👍
@terryjreedy please, check my PR.

@vstinner
Copy link
Member

vstinner commented Oct 1, 2023

I had a similar idea.

I would prefer that --randomize keeps its current behavior: randomize the list of tests. It has a significant impact when tests are run sequentially.

Let's add --no-use-randseed flag to disable setting random.seed, let's always seed random by default

As an user, it's hard to understand this option. I don't understand the use case neither. Is it to increase the entropy of the initial seed? Recently, I increased the rand seed range to make it 10x larger :-)

I suggest to not add such confusing option. Just always set a random seed and display it.

@sobolevn
Copy link
Member Author

sobolevn commented Oct 4, 2023

I've checked all other Random() instances in Lib/test none of them need extra seeding.
Most of them are in test_random, which handles seeds correctly!

@vstinner
Copy link
Member

vstinner commented Oct 4, 2023

I've checked all other Random() instances in Lib/test none of them need extra seeding.

Thanks for checking.

@vstinner vstinner closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants