[Django]-How can I set up django not to use in-memory database during unittest?

5👍

According to the documentation:

By default the test databases get their names by prepending test_ to
the value of the NAME settings for the databases defined in DATABASES.
When using the SQLite database engine the tests will by default use an
in-memory database
(i.e., the database will be created in memory,
bypassing the filesystem entirely!). If you want to use a different
database name, specify NAME in the TEST dictionary for any given
database in DATABASES
.

Specify the NAME key in the TEST dictionary:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        ...
        'TEST': {
            'NAME': '/path/to/the/db/file'
        }
    }
}

Note that for Django 1.6 and below, you should set TEST_NAME instead:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        ...
        'TEST_NAME': '/path/to/the/db/file'
    }
}
👤alecxe

Leave a comment