Welcome to Django PyFixture’s documentation!


  1. Add django_pyfixture into your INSTALLED_APPS.
  2. Create empty <appname>/fixtures/__init__.py file inside your django app called <appname>.
  3. Create your fixtures in files like <appname>/fixtures/foo.py with content similar to this:
# file proj/appname/fixtures/foo.py

from django_pyfixture import PyFixtureBase

class FooData(PyFixtureBase):
    def load_data(self):
        # create your python objects here
  1. Add inheritance into your base test class like this:


    Make sure you put PyFixtureTestCase before DjangoTestCase. Seems that Unittest2-guys didn’t inherit object, so now multi-inheritance via super() doesn’t work good if order isn’t right.

# file proj/utils/test_bases.py

from django_pyfixture import PyFixtureTestCase
from django.test import TestCase as DjangoTestCase

class BaseTestCase(PyFixtureTestCase, DjangoTestCase):
  1. Add py_fixtures list inside your tests like this:

    # file proj/appname/tests/foo_tests.py
    class TestFoo(BaseTestCase):
        py_fixtures = ['foo']
        def test_should_get_list_of_foo(self):
            # do something with foo here
  2. To load some data from terminal use

    python manage.py loaddata_py foo

Additional info


Remember, there’s no magical way to clean-up any side-effects you cause, so if you do something beyond transactions (like writing to redis) – make sure you’ll add cleanup after test or inside base test case. Cleanup method will be added into django-pyfixture later.

Indices and tables

Project Versions

Table Of Contents

This Page