Use more reproducible "random" numbers.

This commit is contained in:
Itamar Turner-Trauring 2021-09-13 09:40:32 -04:00
parent b01c5c7454
commit a482f216a1

View File

@ -18,7 +18,7 @@ if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
# fmt: on # fmt: on
from random import randrange from random import Random
from testtools import skipIf from testtools import skipIf
@ -31,10 +31,15 @@ from .test_system import SystemTestMixin
from .common import AsyncTestCase from .common import AsyncTestCase
# Use random generator with known seed, so results are reproducible if tests
# are run in the same order.
_RANDOM = Random(0)
def _randbytes(length): def _randbytes(length):
# type: (int) -> bytes # type: (int) -> bytes
"""Return random bytes string of given length.""" """Return random bytes string of given length."""
return b"".join([bchr(randrange(0, 256)) for _ in range(length)]) return b"".join([bchr(_RANDOM.randrange(0, 256)) for _ in range(length)])
def new_storage_index(): def new_storage_index():