Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

don't load 'initial_data.json' fixture when testing

Tags:

django

testing

I'm testing a django app not written by myself, which uses two fixtures: initial_data.json and testing.json. Both fixtures files contain conflicting data (throwing an integrity error).

For testing, I've specified TestCase.fixtures = ['testing.json'], but initial_data.json is loaded too.

How can I avoid loading initial_data.json (not renaming it) in the testcase?

like image 968
jmoritz Avatar asked Nov 10 '10 15:11

jmoritz


1 Answers

Quoting from Django Website:

If you create a fixture named initial_data.[xml/yaml/json], that fixture will be loaded every time you run syncdb. This is extremely convenient, but be careful: remember that the data will be refreshed every time you run syncdb. So don't use initial_data for data you'll want to edit.

So I guess there's no way to say "okay, don't load initial data just this once". Perhaps you could write a short bash script that would rename the file. Otherwise you'd have to dig into the Django code.

More info here: http://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures

like image 162
kovshenin Avatar answered Sep 21 '22 08:09

kovshenin