Sven Sven - 1 year ago 91
Bash Question

Django shell: Command to load test fixture data?

Is there an easy way to load fixture data that I usually use in automated test runs in the interactive Django shell?

It might be awkward to have a mixture of model data that come from the database and others that come from a fixture. In my case, I have some read-only tables and wand to experiment with some data that I can discard afterwards.

I can probably load the fixture files like described here, but that's a bit cumbersome for repeated use...

Answer Source

ilardm's answer points in the right direction, specifically what you want is:

from import call_command
call_command('loaddata', 'fixture_name.json')

Edit: But the correct way to include fixtures in test cases is like this:

class TestThis(TestCase):
    fixtures = ['myfixture.json']

    def setUp(self):
        # Ready to test
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download