我想在我的测试中使用一些固定装置。
我有cms_sample
应用程序和一个固定文件夹,里面有:cms_sample_data.xml
我在我的中使用以下内容test.py
:
class Functionality(TestCase):
fixtures = ['cms_sample_data']
我确实使用TestCase
和django.tests
不unittest
使用.
但是没有加载固定装置。我错过了什么?
我想在我的测试中使用一些固定装置。
我有cms_sample
应用程序和一个固定文件夹,里面有:cms_sample_data.xml
我在我的中使用以下内容test.py
:
class Functionality(TestCase):
fixtures = ['cms_sample_data']
我确实使用TestCase
和django.tests
不unittest
使用.
但是没有加载固定装置。我错过了什么?
忘记了 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.
你在使用多个数据库吗?如果是这样,您的测试可能需要设置multi_db 属性:
multi_db = True
在 Django 的文档上学习这个主题时,我遇到了类似的问题。我如何解决它是将存储我的灯具的格式文件更改为正确的格式。最初,我保存的夹具是一个名为“test_db.json”的普通文本文件。意识到这一点后,我将“.txt”文件更改为“.JSON”文件。一旦我输入“./manage.py test”命令,它就开始自行加载夹具。