samedi 18 novembre 2017

How to prevent FactoryBoy from reusing object of a SubFactory?

I have the following factories:

class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = get_user_model()


class ProProfileFactory(factory.DjangoModelFactory):
    user = factory.SubFactory(UserFactory)
    class Meta:
        model = ProfessionalProfile


class UserProfileFactory(factory.DjangoModelFactory):
    user = factory.SubFactory(UserFactory)
    class Meta:
        model = UserProfile

When I inject both pro and user profiles they are associated with the same user:

def test_should_create_project(pro_profile, user_profile):
    assert user_profile.user != pro_profile.user

This test fail.

How can I make factory boy create a new user for each profile?

I'm using Django 1.11, pytest 3.2.2, pytest-django 3.1.2, pytest-factoryboy 1.3.1

Aucun commentaire:

Enregistrer un commentaire