6

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?

1 Answer 1

13

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',
        },
    },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.