How to use different database engines in Django for testing and production How to use different database engines in Django for testing and production sqlite sqlite

How to use different database engines in Django for testing and production


One option would be to check sys.argv for the test argument in settings.py:

if 'test' in sys.argv:    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'    DATABASES['default']['NAME'] = 'databasename.db3'

Though, as a side note: strictly speaking, it is not really a good idea to have different database backends for testing and for development/stage/production. You may encounter database-specific "special" cases, that can cost you a lot of time and headache.


You don't need to do any hacks. "--settings" - this is what you're looking for.

python manage.py test APP --settings settings.localpython manage.py test APP --settings settings.production


Whenever possible it's always a good idea to use the same setup in production and test. It makes for better testing. I great way to deal with tests running slowly is to use django-nose. It lets you reuse previously created test databases. This can super speed up test runs. Check out enabling database reuse in the docs. An example is as follows:

REUSE_DB=1 ./manage.py test