Skip to content

libregrtest should always set random.seed #110171

Closed

Description

@sobolevn

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

Activity

  1. added
    type-featureA feature request or enhancement
    testsTests in the Lib/test dir
    on Oct 1, 2023
  2. self-assigned this
    on Oct 1, 2023
  3. added 2 commits that reference this issue on Oct 1, 2023
  4. terryjreedy commented on Oct 1, 2023

    @terryjreedy
    Member

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

  5. sobolevn commented on Oct 1, 2023

    @sobolevn
    MemberAuthor

    Yes 👍
    @terryjreedy please, check my PR.

  6. vstinner commented on Oct 1, 2023

    @vstinner
    Member

    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.

  7. added a commit that references this issue on Oct 4, 2023
  8. sobolevn commented on Oct 4, 2023

    @sobolevn
    MemberAuthor

    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!

  9. vstinner commented on Oct 4, 2023

    @vstinner
    Member

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

    Thanks for checking.

  10. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions