【发布时间】:2012-07-28 16:11:05
【问题描述】:
我安装了 django-nose 1.0 作为 Django 1.3.1 项目的测试运行器。我正在遵循关于仅测试模型的说明 on the pypi page。
这是我的 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”的任何表)不存在。
关于为什么只测试模型没有加载的任何想法?
【问题讨论】:
-
我现在遇到了与 1.5 相同的错误。请问你是怎么解决的?
标签: django-nose