3
我想要创建集成测试,以便我可以在数据库中创建1000个单一模型的记录。在Django中设置测试数据库
对于我的settings.py文件,我指定在运行测试时使用相同的数据库default
。
if 'test' in sys.argv or 'test_coverage' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'TableName', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'password', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
}
}
当我运行命令python manage.py test <app>
我得到一个错误,说明我有跑两会。
Got an error creating the test database: source database "template1" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
的数据库测试被创建和销毁,如果我创建记录,这是否意味着当测试完成时它们将被删除? – Warz
是的,这是正确的。将为您创建一个名为'test_TaleeboBixin'的新数据库(因为您的实际数据库名为'TaleeboBixin')。并且这个数据库将在测试运行完成时被删除。 –
我真的想创建不会消失的模型的测试,如果测试dB消失,我有什么选择呢? – Warz