1

I hope not to make a fool of myself by re-asking this question, but I just can't figure out why my fixtures are not loaded when running test. I am using python 2.7.5 and Django 1.5.3.

I can load my fixtures with python manage.py testserver test_winning_answers, with a location of survey/fixtures/test_winning_answers.json.

Creating test database for alias 'default'...
Installed 13 object(s) from 1 fixture(s)
Validating models...

0 errors found

My test class is doing the correct import:

from django.test import TestCase
class QuestionWinningAnswersTest(TestCase):

    fixtures = ['test_winning_answers.json']
    ...

But when trying to run the test command, it cannot find them:

python manage.py test survey.QuestionWinningAnswersTest -v3
...
Checking '/django/mysite/survey/fixtures' for fixtures...
...
No json fixture 'initial_data' in '/django/mysite/survey/fixtures'.
...
Installed 0 object(s) from 0 fixture(s)
...

I suspect I am missing something obvious, but cannot quite figure it out... any suggestion would be appreciated. Thanks!

Phil
  • 879
  • 2
  • 10
  • 23

3 Answers3

0

It looks like it is trying and failing to find a file called 'initial_data' in '/django/mysite/survey/fixtures' rather than failing to load 'test_winning_answers.json'

Try adding a file called 'initial_data.json' containing just '[]'

Jonathan
  • 21
  • 3
  • This works indeed `Installing json fixture 'initial_data' from '/django/mysite/survey/fixtures'. CommandError: No fixture data found for 'initial_data'. (File format may be invalid.)`. – Phil Oct 16 '13 at 15:17
  • Of course I still don't know why it won't accept the fixture file I would like to use. – Phil Oct 16 '13 at 16:52
0

I am not sure why, but python manage.py test survey -v3 displays Installed 0 object(s) from 0 fixture(s).

Following mariodev's recommendations, I looked into django/test/testcases.py, and changed the call_command('loaddata'...) to use verbosity=3. This clearly showed me that the fixture was properly loaded:

Installing json fixture 'test_winning_answers' from '/django/mysite/survey/fixtures'.
Installed 13 object(s) from 1 fixture(s)

The error that prompted me to look into fixtures loading was actually a typo I had made...

Phil
  • 879
  • 2
  • 10
  • 23
0

In my case, the app was missing from INSTALLED_APPS configuration for Django to find the fixture file.

kta
  • 19,412
  • 7
  • 65
  • 47