The database name used when running pytest-django is prefixed with "test_", but I want it to be the same as the database name normally used by model.
Unfortunately, the method wasn't written on the official site, so I read the source and looked it up.
The following are assumed as usage examples.
settings.py
DATABASES = {
'default': {
'NAME': 'app_data',
}
When py.test --create-db
is executed with the above settings, test_app_data
is created and used, but I want to use ʻapp_data`.
Log in to mysql and check the table
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| app_data |
| test_app_data |
+--------------------+
If you write the following in DATABASES
of settings.py
, it's OK.
Added dict with 'TEST'
as a key in the same row as 'NAME'
.
Specify the DB name in the dict with 'NAME'
as the key.
settings.py
DATABASES = {
'default': {
'NAME': 'app_data',
'TEST': {
'NAME': 'app_data',
}
}
Specify the DB name using 'TEST_NAME'
as a key in the same column as 'NAME'
.
settings.py
DATABASES = {
'default': {
'NAME': 'app_data',
'TEST_NAME': 'app_data',
}
Recommended Posts