【发布时间】:2015-12-12 15:20:44
【问题描述】:
我正在尝试设置 LiveServerTestCase。
为此,我在我的测试类中创建了一个用户
class ExampleTest(LiveServerTestCase):
user = User.objects.create_superuser('Testuser','test@user.com','1234')
user.save()
.
.
.(rest of the test)
没有此行,服务器和测试将启动,但显然它无法登录,因为之前没有创建用户。
但是有了这条线,我得到了一个
django.core.exceptions.ImproperlyConfigured: settings.DATABASES
is improperly configured. Please supply the NAME value.
错误。
我是否需要在 settings.py 中为 LiveServerTestCase 设置服务器,如果需要,使用哪些值或在哪里可以找到它们?
更新:
我正在运行这个测试
python manage.py test
所以它自己建立了一个数据库,我不必在 settings.py 中定义,或者我错了。
更新2:
我已经定义了一个“生产”数据库(在我问这个问题之前),它看起来像这样:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': 'localhost', # 10.1.2.41
'NAME': 'pim_testdatabase',
'USER': 'postgres',
'PASSWORD': '1234',
'PORT': '5432',
'HAS_HSTORE': True,
'TEST':{
'NAME': 'test_pim_testdatabase'
},
},
}
仍然出现异常。
【问题讨论】:
标签: python django python-3.x selenium testing