pytest-factoryboy icon indicating copy to clipboard operation
pytest-factoryboy copied to clipboard

Factory not registering as fixture

Open YoungiiJC opened this issue 5 years ago • 1 comments

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)

YoungiiJC avatar Sep 01 '20 09:09 YoungiiJC

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.

voyc-jean avatar Dec 01 '20 16:12 voyc-jean

Hi apologies for getting back to this only now, I hope the issue was fixed. If not, I'll re-open the issue.

youtux avatar Jul 23 '23 20:07 youtux