Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why django test --keep-db works with postgres database but not with default sqlite3

I'm testing Django (v1.11.4) application in two setups of database: 1) postgres database running in docker container or 2) sqlite3 as (default database)

When running tests with --keepdb option I observe different behavior for these two setups: for postgres --keepdb works as expected (there is no database creation and running test is fast) but for sqlite3 database --keepdb seems not working (for each run of the test there is creation of database). Is it possible to have --keepdb working with sqlite3? If so any idea what settings might affect behavior described as above?

like image 957
izkeros Avatar asked Dec 13 '22 21:12

izkeros


1 Answers

By default, Django uses an in-memory database when testing sqlite. This means that the test database isn't persistent. You can override this behaviour in your DATABASES setting by specifying a test name:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite',
        'NAME': 'db.sqlite3',
        'TEST': {
            'NAME': 'testdb.sqlite3',
        },
    },
}
like image 139
Alasdair Avatar answered May 03 '23 13:05

Alasdair