I have a very simple scenario
from django.test import TestCase
class BaseTest(TestCase):
fixtures = ('users.json',)
...
class SpecificTest(BaseTest):
fixtures = ('transactions.json',)
...
transactions has an FK to users and when SpecificTest attempts to load the fixtures I get an IntegrityError
IntegrityError: Problem installing fixtures:
The row in table 'app_transactions' with primary key '1' has an
invalid foreign key: app_transactions.user_id contains a value '30'
that does not have a corresponding value in app_user.id.
This error means that the users.json
fixture loaded in BaseTest
was not loaded before the transactions.json
fixtures (as you might expect). My question is, what is the proper way to load fixtures when subclassing tests ?
Django 1.7
When you override
fixtures
in a subclass, it replaces the fixtures, it doesn't extend them.You can either explicitly repeat the fixtures:
or refer to
BaseTest.fixtures
in your subclass: