Skip to content

Are factory.django.DjangoModelFactory fixtures in conftest.py available across applications? #52

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

Closed
tony opened this issue Aug 24, 2017 · 2 comments

Comments

@tony
Copy link
Member

tony commented Aug 24, 2017

pytest-dev/pytest-django#508

I'm using factory_boy with https://github.com/pytest-dev/pytest-django.

python: 3.6.2
django: 1.11.4
pytest-django: 3.1.2
factory-boy: 2.8.1 (downgraded due to #47 (comment))
pytest-factoryboy: 1.3.1

Here's my app1/conftest.py:

# -*- coding: utf-8 -*-
import factory
import pytest
from django.contrib.auth import get_user_model
from django.core.management import call_command
from pytest_factoryboy import register

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

    username = factory.Sequence(lambda n: "user%03d" % n)
    password = factory.Sequence(lambda n: "pass%03d" % n)

register(UserFactory)

This makes user available as a fixture for me. However, it only works in tests in the same application, not project-wide (in different django application test directories).

Am I doing it wrong, then? I'm trying to narrow down if this is a mistake on my end, a bug, a potential feature, or expected behavior.

@tony
Copy link
Member Author

tony commented Aug 24, 2017

By the way, here's my workaround:

Apparently the fixture user created by register is only available in the application the conftest.py is in, not project-wide.

So, I create a second conftest.py in the application missing the user fixture to re-register the fixture:

app2/conftest.py:

# -*- coding: utf-8 -*-
from pytest_factoryboy import register

from ...core.tests.conftest import UserFactory

register(UserFactory)

@tony
Copy link
Member Author

tony commented Oct 16, 2020

I will close this issue for now since I don't remember the context / am using the same test suite as a few years back.

@tony tony closed this as completed Oct 16, 2020
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