【发布时间】:2014-01-08 11:00:08
【问题描述】:
我有一个 Django 应用程序,它基本上看起来像这样:
app/
fixtures/
file.json
...
tests/
__init__.py
settings.py
tests.py
我已经在tests.py 中加载了我的夹具,它基本上是这样的:
from django.test import TestCase
class TestFile(TestCase):
fixtures = ['file.json']
...
我的夹具文件如下所示:
[
{
"model": "sites.site",
"pk": 100,
"fields": {
"domain": "myproject.mydomain.com",
"name": "My Project"
}
},
]
我的settings.py 在INSTALLED_APPS 中有django.contrib.sites。
但是,当我尝试使用 py.test 运行我的测试时,这个夹具似乎被忽略了,因为我使用 ipdb 中断了我的一些测试,查询 Site.objects.all(),而我的夹具站点不是显示。可能是什么问题?
我运行我的测试:py.test --ds=app.tests.settings --pyargs app.tests.tests -s(-s 用于允许ipdb 的输出)。
`
【问题讨论】:
-
使用 manage.py loaddata app/fixtures/file.jsson 是否正确加载了灯具?
-
没有,但我发现我忘记在
INSTALLED_APPS中包含app...现在灯具已安装,我可以看到我的灯具站点。
标签: python django fixtures pytest