Python 在Django测试中,夹具似乎被忽略了
我有一个Django应用程序,基本上是这样的:Python 在Django测试中,夹具似乎被忽略了,python,django,fixtures,pytest,Python,Django,Fixtures,Pytest,我有一个Django应用程序,基本上是这样的: app/ fixtures/ file.json ... tests/ __init__.py settings.py tests.py from django.test import TestCase class TestFile(TestCase): fixtures = ['file.json'] ... [ {
app/
fixtures/
file.json
...
tests/
__init__.py
settings.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"
}
},
]
我已经在tests.py中加载了我的fixture,它基本上如下所示:
app/
fixtures/
file.json
...
tests/
__init__.py
settings.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"
}
},
]
我的夹具文件如下所示:
app/
fixtures/
file.json
...
tests/
__init__.py
settings.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中有django.contrib.sites
但是,当我尝试使用py.test运行测试时,这个fixture似乎被忽略了,因为我使用ipdb中断了一些测试,查询Site.objects.all,并且没有显示我的fixture站点。有什么问题吗
我使用:py.test-ds=app.tests.settings-pyargs app.tests.tests-s-s运行测试,用于允许ipdb的输出。
`问题似乎实际上是一个非常明显的细节:我忘记了在我的settings.py文件中包含app in INSTALLED_APPS。夹具现在已安装,我可以看到我的夹具站点 是否使用manage.py loaddata app/fixtures/file.jsson正确加载装置?否,但我发现我忘记在已安装的应用程序中包含应用程序…现在装置已安装,我可以看到我的装置站点。