我有 Django 1.4。在我的 test.py 中,我已经导入了必需的 TestCase:
from django.test import TestCase
为了隔离问题,我添加了以下行:
fixtures = ['westeros']
默认示例测试用例,即
class SimpleTest(TestCase):
fixtures = ['westeros']
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
使用 django-admin.py dumpdata,我在customers/fixtures目录中创建了一个名为“westeros”的fixture文件,其中“customers”是settings.INSTALLED_APPS中列出的应用程序。
当我运行测试时,无论多么详细,Django 都会简单地忽略固定装置并通过 test_basic_addition
测试。没有错误,没有夹具加载。就好像 TestCase 导入不存在一样。关于可能出什么问题或如何调试这个问题有什么想法吗?
最佳答案
像您所做的那样,在定义fixtures
时省略扩展名是可以的,即
fixtures = ['westeros']
但是,fixture 文件本身必须具有与其序列化程序相对应的扩展名,例如 westeros.json
、westeros.json.zip
或 westeros.xml
分别表示 json、压缩的 json 或 xml。
关于Django 忽略了我的 TestCase 装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11871327/