我安装了 django-nose 1.0 作为 Django 1.3.1 项目的测试运行程序。我正在遵循pypi 页面上有关仅测试模型的说明。
这是我的 settings.py testrunner 配置:
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
我已经使用这个 testrunner 运行了几个月的测试没有问题。现在我正在尝试测试一个抽象类,并且我正在使用仅测试模型,但是我编写的特定测试会引发错误。
根据文档,我只需要将测试类包含在测试期间导入的文件之一中。我将测试放在“测试”文件夹中,并分解为几个较小的测试文件。这是我的测试/model_tests.py(模型和应用程序出于工作原因故意重命名):
from django.tests import TestCase
from myapp.models import AbstractFoo
class Foo(AbstractFoo):
pass
class TestFoo(TestCase):
def setUp(self):
self.foo = Foo.objects.create(name="Tester",
description="This is a test", ...)
... [tests follow]
我在 setUp 的第一行收到一个错误:
DatabaseError: relation "tests_foo" does not exist
LINE 1: INSERT INTO "tests_foo" ("name", "description", "display...
如果我在测试中设置一个断点并检查数据库,则表“tests_foo”(或任何名称中带有“foo”的表)不存在。
关于为什么只测试模型没有加载的任何想法?