pytest-factoryboy
pytest-factoryboy copied to clipboard
Factory not registering as fixture
Hey there,
I'm trying to set up a basic test per this example: https://pytest-factoryboy.readthedocs.io/en/latest/#integration
When my tests check whether company_factory is an instance of CompanyFactory, the test fails.
Why isn't company_factory being instantiated?
Here's my code:
# tests/test_company.py
import pytest
from .factories import CompanyFactory
from project.apps.company.models import Company
def test_company_factory(company_factory):
assert isinstance(company_factory, CompanyFactory) # passes
def test_company_model(db, company):
assert isinstance(company, Company) # fails
# message: where False = isinstance(<class 'tests.factories.CompanyFactory'>, CompanyFactory)**
# tests/factories.py
class CompanyFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'company.Company'
name = 'company'
# other attributes ...
# tests/conftest.py
import pytest
from pytest_factoryboy import register
from .factories import CompanyFactory
register(CompanyFactory)
I'm having a similar issue, though in my case a company instance isn't available as a fixture at all. Only CompanyFactory is registered as company_factory.
Hi apologies for getting back to this only now, I hope the issue was fixed. If not, I'll re-open the issue.