loading fixtures for django tests
I want to use some fixtures in my tests.
I have cms_sample
app and a fixt开发者_开发技巧ures folder inside with: cms_sample_data.xml
I use the following in my test.py
:
class Functionality(TestCase):
fixtures = ['cms_sample_data']
I do use TestCase
of django.tests
and not unittest
.
But the fixtures are not loaded. What am I missing?
Forgot the xml-extension?
class Functionality(TestCase): fixtures = ['cms_sample_data.xml']
perhaps your cms_sample_data file is error. you can use this comand: manage.py loaddata cms_sample_data
to check the file.
I had a similar problem while learning about this subject on Django's docs. How I solved it was changing the format file that stored my fixture to the proper format. Originally, I saved the fixture was an ordinary text file with the name "test_db.json". Once I realized this, I changed the ".txt" file into a ".JSON" file. It began to load the fixture on its own once I typed in the "./manage.py test" command.
Are you using multiple databases? If so, your test might need to set the multi_db property:
multi_db = True
精彩评论