loading fixtures for django tests

I want to use some fixtures in my tests.

I have cms_sample app and a fixtures 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?


忘记了xml扩展名?

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.

链接地址: http://www.djcxy.com/p/52296.html

上一篇: 在django单元测试中加载装置

下一篇: 为django测试加载装置