11from __future__ import annotations
22
33import argparse
4- import hashlib
54import random
65import sys
76from functools import lru_cache
@@ -160,8 +159,7 @@ def _reseed(config: Config, offset: int = 0) -> int:
160159 baker_random .setstate (random_state )
161160
162161 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 )
165163
166164 if entrypoint_reseeds is None :
167165 eps = entry_points (group = "pytest_randomly.random_seeder" )
@@ -172,15 +170,6 @@ def _reseed(config: Config, offset: int = 0) -> int:
172170 return seed
173171
174172
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-
184173def pytest_report_header (config : Config ) -> str :
185174 seed = config .getoption ("randomly_seed" )
186175 _reseed (config )
@@ -189,7 +178,7 @@ def pytest_report_header(config: Config) -> str:
189178
190179def pytest_runtest_setup (item : Item ) -> None :
191180 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 )
193182
194183
195184def pytest_runtest_call (item : Item ) -> None :
@@ -199,7 +188,7 @@ def pytest_runtest_call(item: Item) -> None:
199188
200189def pytest_runtest_teardown (item : Item ) -> None :
201190 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 )
203192
204193
205194@hookimpl (tryfirst = True )
0 commit comments