Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducible randomness does not seem to work with distributed tests #1014

Open
GergelyKalmar opened this issue Apr 13, 2023 · 0 comments
Open

Comments

@GergelyKalmar
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant