Question

I have a Django app which basically looks like this:

app/
    fixtures/
        file.json
    ...
    tests/
        __init__.py
        settings.py
        tests.py

I have loaded my fixture in tests.py, which basically looks like this:

from django.test import TestCase

class TestFile(TestCase):

    fixtures = ['file.json']

    ...

My fixture file looks like this:

[
    {
        "model": "sites.site", 
        "pk": 100, 
        "fields": {
          "domain": "myproject.mydomain.com", 
          "name": "My Project"
        }
    },
]

I have django.contrib.sites in my settings.py in INSTALLED_APPS.

However, when I try to run my tests with py.test, this fixture seem to be ignored, since I break in some of my tests with ipdb, query for Site.objects.all(), and my fixture site isn't shown. What can be the problem?

I run my tests with: py.test --ds=app.tests.settings --pyargs app.tests.tests -s (-s is for allowing ipdb's output). `

Was it helpful?

Solution

It seems that the problem was in fact a very obvious detail: I have forgotten to include app in INSTALLED_APPS in my settings.py file. The fixture is now installed and I can see my fixture site.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top