[Django]-Why does django require that I create a mysql database just to run the tests?

1👍

This is because Django loads the settings.py file for running the test suite. You can create a separate settings.py file and use it at the time you run the tests. As an example from the django site:

--settings=test_sqlite

assuming you had a settings.py file called test_sqlite.

Go here for more information:

https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/

1👍

If you run tests frequently put the following code in your settings.py:

import sys

if 'test' in sys.argv:
    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'test'
    }
}

1👍

I use almost the same solution for test, like @Simon Bächler, but instead of real database

'NAME': 'test', 

I use

'NAME':' :memory:,

So it use memory to handle test operations, and thats why it doesn’t always create/update/delete the db.

👤Igor

Leave a comment