Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.6.1未加载Unittest的夹具_Python_Django_Unit Testing_Django Fixtures_Django Unittest - Fatal编程技术网

Python Django 1.6.1未加载Unittest的夹具

Python Django 1.6.1未加载Unittest的夹具,python,django,unit-testing,django-fixtures,django-unittest,Python,Django,Unit Testing,Django Fixtures,Django Unittest,Django没有为以下测试加载夹具 from django.test import TestCase class DevViewsTests(TestCase): fixtures = ['device/fixtures/test_device.json'] def setUp(self): self.client = Client() self.username = 'cws' self.email = 'alain.stu

Django没有为以下测试加载夹具

from django.test import TestCase

class DevViewsTests(TestCase):

    fixtures = ['device/fixtures/test_device.json']

    def setUp(self):
        self.client = Client()
        self.username = 'cws'
        self.email = 'alain.sturzenegger@gmail.com'
        self.password = 'cws123'
        self.test_user = User.objects.create_user(self.username, self.email, self.password)
        login = self.client.login(username=self.username, password=self.password)
        self.assertEqual(login, True)

    def test_device_list(self):

        url = reverse('device-overview')
        response = self.client.get(url)
        logger.debug('GET[%s]:[%s]', url, response.status_code)

        self.assertQuerysetEqual(response.context['device_list'], ['<device: Device Test 1>'])
我的test_device.json文件如下

[
{
    "pk": 1, 
    "model": "device.device", 
    "fields": {
        "owner": 1, 
        "phone": "+41765687755", 
        "name": "Device Test 1", 
        "access_code": "1234"
    }
}
]
文件结构是

cws
--device
--fixtures
----test_device.json
知道我做错了什么吗?请根据以下内容提供建议:

创建装置并将其放置在 您可以通过以下方式在单元测试中使用其中一个已安装的应用程序 在django.test.TestCase上指定fixtures类属性 子类:

只需指定文件名,而不是项目目录中的相对路径:

fixtures = ['test_device.json']

如果您指定
fixtures=['test\u device.json']
,会发生什么?非常感谢,它成功了。我没有在settings.py文件中设置FIXTURE_DIRS变量,所以我使用的是相对路径,那么它是如何获得路径的?@falsetru:你知道FIXTURE=['device/fixtures/test_device.json']在这里不起作用的原因吗?
fixtures = ['test_device.json']