Sometimes we need to write test with initial data
1 2 3 4 |
# settings.py FIXTURE_DIRS = [ os.path.join(BASE_DIR, 'fixtures/myapp'), ] |
For this setting as example, we can load initial data by
1 2 |
$ python manage.py loaddata data_json $ python manage.py loaddata data_yaml.yaml |
And we need to do setup in test cases
1 2 3 4 5 6 7 8 9 10 |
from django.test import TestCase from django.core.management import call_command class MyTestCase(self): def setUp(self): call_command('loaddata', 'data_json', verbosity=0) call_command('loaddata', 'data_yaml.yaml', verbosity=0) def test_something(self): pass |