Reproducible randomness does not seem to work with distributed tests
GergelyKalmar opened this issue · comments
Description
I've followed the advice at https://factoryboy.readthedocs.io/en/stable/recipes.html#using-reproducible-randomness, and it seems that when I run my test suite serially it works, however, whenever I run my test suite via pytest-xdist I get flakiness with the Faker
attributes.
To Reproduce
I created some standard factories (see below) and use them as fixtures in my pytest tests via pytest-factoryboy (https://pytest-factoryboy.readthedocs.io/en/stable/).
Model / Factory code
from django.contrib.auth.hashers import make_password
from factory import Faker, LazyFunction, random as factory_random
from factory.django import DjangoModelFactory
factory_random.reseed_random(42)
class UserFactory(DjangoModelFactory):
username = 'user'
password = LazyFunction(lambda: make_password('local'))
first_name = Faker('first_name')
last_name = Faker('last_name')
email = Faker('email')
class Meta:
model = User
The issue
The faker attributes are changing between tests.
Note
I've started wondering whether every test has their own random number generator or if they share the generator instance. I could imagine that if they share the generator instance then a change in the order of the tests might produce this sort of flakiness.