djangodjango-testing

How to configure "manage.py test" to run with sqlite? (Django)


I use Postgres for production and development, but I'd like to use sqlite to run some tests. I don't see an easy way to configure one engine for tests and another for dev / production. Am I missing something? Is there an environment variable to set, or some easy way that doesn't involve another settings.py file?


Solution

  • Append the following lines in your settings:

    import sys
    if 'test' in sys.argv or 'test_coverage' in sys.argv: #Covers regular testing and django-coverage
        DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
    

    Make sure your actual database setting comes before them.