我正在尝试使用 django-discover-runner 来测试我的应用程序。它基本上是一个 WebService 前端,因此它不包含数据库,显然 django-discover-runner 不喜欢这样。
查看 other questions ,我已经看到,对于普通的 Django,我应该继承 DjangoTestSuiteRunner
并设置 settings.TEST_RUNNER
。效果很好。但是 django-discover-runner 使用它自己的 discover_runner.DiscoverRunner
类,所以我尝试了这个:
from discover_runner import DiscoverRunner
class DBLessTestRunner(DiscoverRunner):
def setup_databases(self):
pass
def teardown_databases(self, *args):
pass
但是这不起作用。我收到此错误消息:
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
知道如何让 django-discover-runner 在没有数据库的情况下工作吗?
最佳答案
在 Django 1.6 中,标准 Django TestCase 继承自 TransactionTestCase,它尝试访问数据库。
要解决测试类中的问题,请继承 SimpleTestCase 而不是 TestCase:
from django.test import SimpleTestCase
class TestViews(SimpleTestCase):
...
您现在应该能够运行测试而无需设置数据库。
关于django - 在没有数据库的情况下使用 django-discover-runner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18316724/