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