Tests not loading initial_data fixtures

8 views
Skip to first unread message

Sam Lai

unread,
Oct 3, 2013, 2:49:05 AM10/3/13
to django-users
I'm trying to test a Django management command in app X that parses
data files and inserts data into models that are located in apps Y and
Z. Apps Y and Z have initial_data.json files in them. On running my
test however, it seems that my initial_data fixtures are not being
loaded.

I could specify the initial_data fixtures manually (presumably I can
do ../) using the 'fixtures' variable in my TestCase, but that isn't
very DRY and becomes tedious when more apps are introduced with their
own initial_data.

I tracked this down to a change that Russell made 3 years ago
(https://github.com/django/django/commit/b31a1b99261d05bf8a34495ee9faf4d6592b8b36).
The commit message and content explains why *custom SQL* fixtures
aren't loaded automatically during testing, but says nothing about why
xml/yaml/json fixtures are no longer loaded either.

All django-users threads that I can find on this refer to the
situation prior to this change, and state that initial_data fixtures
*were* loaded.

What's the reason for the change? I thought initial_data is designed
for data that should always be in the database, so this is a bit odd.
Can't really find anything in the docs that mentions this either.

Thanks,

Sam

Sam Lai

unread,
Oct 3, 2013, 3:07:57 AM10/3/13
to django-users
Ah, turns out all you have to do is specify -

fixtures = [ 'initial_data' ]

... in the TestCase and it'll load all the initial_data fixtures from
all apps. Still a bit odd that loading initial_data fixtures isn't the
default in tests though.
Reply all
Reply to author
Forward
0 new messages