1
1
from __future__ import annotations
2
2
3
3
import argparse
4
- import hashlib
5
4
import random
6
5
import sys
7
6
from functools import lru_cache
@@ -160,8 +159,7 @@ def _reseed(config: Config, offset: int = 0) -> int:
160
159
baker_random .setstate (random_state )
161
160
162
161
if have_numpy : # pragma: no branch
163
- numpy_seed = _truncate_seed_for_numpy (seed )
164
- np_random .seed (numpy_seed )
162
+ np_random .seed (seed % 2 ** 32 )
165
163
166
164
if entrypoint_reseeds is None :
167
165
eps = entry_points (group = "pytest_randomly.random_seeder" )
@@ -172,15 +170,6 @@ def _reseed(config: Config, offset: int = 0) -> int:
172
170
return seed
173
171
174
172
175
- def _truncate_seed_for_numpy (seed : int ) -> int :
176
- seed = abs (seed )
177
- if seed <= 2 ** 32 - 1 :
178
- return seed
179
-
180
- seed_bytes = seed .to_bytes (seed .bit_length (), "big" )
181
- return int .from_bytes (hashlib .sha512 (seed_bytes ).digest ()[: 32 // 8 ], "big" )
182
-
183
-
184
173
def pytest_report_header (config : Config ) -> str :
185
174
seed = config .getoption ("randomly_seed" )
186
175
_reseed (config )
@@ -189,7 +178,7 @@ def pytest_report_header(config: Config) -> str:
189
178
190
179
def pytest_runtest_setup (item : Item ) -> None :
191
180
if item .config .getoption ("randomly_reset_seed" ):
192
- _reseed (item .config , _crc32 (item .nodeid ) - 1 )
181
+ _reseed (item .config , ( _crc32 (item .nodeid ) - 1 ) % 2 ** 32 )
193
182
194
183
195
184
def pytest_runtest_call (item : Item ) -> None :
@@ -199,7 +188,7 @@ def pytest_runtest_call(item: Item) -> None:
199
188
200
189
def pytest_runtest_teardown (item : Item ) -> None :
201
190
if item .config .getoption ("randomly_reset_seed" ):
202
- _reseed (item .config , _crc32 (item .nodeid ) + 1 )
191
+ _reseed (item .config , ( _crc32 (item .nodeid ) + 1 ) % 2 ** 32 )
203
192
204
193
205
194
@hookimpl (tryfirst = True )
0 commit comments