Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Reseed RNG before each test#833

Closed
casperisfine wants to merge 1 commit intominitest:masterfrom
Shopify:reseed-random-before-each-test
Closed

Reseed RNG before each test#833
casperisfine wants to merge 1 commit intominitest:masterfrom
Shopify:reseed-random-before-each-test

Conversation

@casperisfine
Copy link

This ensure that for a given --seed value, a test will always start from the same seed.

Otherwise previous tests using the RNG, would leak state.

This is something we had for a very long time as a global setup, I figured it made sense upstream.

A recent commit to ruby reminded me of it: ruby/ruby@7c1553e

This ensure that for a given `--seed` value, a test
will always start from the same seed.

Otherwise previous tests using the RNG, would leak state.
@zenspider
Copy link
Collaborator

I dunno about this one. I suspect it'll break a lot of tests out there.

I have sranded before shuffling classes and methods for each runnable so that will stabilize that aspect (previously user/test use of srand could throw run order off)...

without more analysis to show that this won't "break the world" I think I'd rather leave it up to the user/test to do it themselves. I've added Minitest.seed in order to make this more readily available.

@zenspider
Copy link
Collaborator

I consider this resolved with the addition of Minitest.seed. Jean? Anything to add?

@byroot
Copy link

byroot commented Jan 15, 2026

I still think it's more valuable to do it before each test so that a test that flakes because of Random can be reproduced consistently by providing the same seed, regardless of whether it's run alone or with the entire "Runable".

@zenspider
Copy link
Collaborator

I agree that could eliminate certain types of errors, but it could introduce others as well. By making the seed available the user can opt in where applicable:

def setup
  super
  srand Minitest.seed
end

@byroot
Copy link

byroot commented Jan 17, 2026

Not really not, but I don't care to argue anymore. Anyways, I no longer use Minitest when I can avoid it, so no longer my problem.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants