The company I work at has a test server which houses all test data. I'm attempting to add some much needed unit tests that reference our Django database on the test server. The problem I'm having is the test database is being created instead of pointing to the database I've provided. I had tried setting the database if test in the system arguments like this:
if 'test' in sys.argv:
DATABASES = {
'default': { # VM Testing
'ENGINE': 'sql_server.pyodbc',
'NAME': 'x',
'USER': 'x',
'PASSWORD': "x",
'HOST': 'x.x.x.x', #
'PORT': '',
'OPTIONS': {
'driver': 'FreeTDS',
'dsn': 'mssql_staging_1',
'extra_params': 'TDS_VERSION=8.0',
'use_legacy_datetime': False
},
},
}
DEBUG = False
TEMPLATE_DEBUG = False
And while it makes it into the this if statement, the test database is still created when running python manage.py test. Any advice? And FWIW all my tests to this point are using DRF and its APITestCase class. Thanks!
EDIT:
I tried running python manage.py test -k But Django is still using the default test database. I threw in a set trace to check, no objects were found. The terminal output was:
Using existing test database for alias 'default'...
Here is my updated updated settings:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'x',
'USER': 'x',
'PASSWORD': "x",
'HOST': 'x.x.x.x',
'PORT': '',
'OPTIONS': {
'driver': 'FreeTDS',
'dsn': 'mssql_staging_1',
'extra_params': 'TDS_VERSION=8.0',
'use_legacy_datetime': False
}
},
'replica': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'x',
'USER': 'x',
'PASSWORD': "x",
'HOST': 'x.x.x.xreplica',
'PORT': '',
'OPTIONS': {
'driver': 'FreeTDS',
'dsn': 'mssql_staging_1',
'extra_params': 'TDS_VERSION=8.0',
'use_legacy_datetime': False
},
'TEST': {
'MIRROR': 'default',
}
}
}