Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30084 closed Bug (invalid)

Setting DATABASES['default']['TEST']['engine'] to SQLite does not cause Django to use an in-memory database as expected

Reported by: mrts Owned by: nobody
Component: Testing framework Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Preconditions

Given the following settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'database',
        ...
        'TEST': {
            'ENGINE': 'django.db.backends.sqlite3',
        }
    }
}

Actual

When I run ./manage.py test in a restricted environment, then I get the following error:

$ ./manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database

Type 'yes' if you would like to try deleting the test database 'test_database', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: database "test_database" does not exist

Expected

The documentation says:

The default test database names are created by prepending test_ to the value of each NAME in DATABASES. When using SQLite, the tests will use an in-memory database by default (i.e., the database will be created in memory, bypassing the filesystem entirely!).

Thus, my expectation was that setting DATABASES['default']['TEST']['engine'] to SQLite will use an in-memory database.

Change History (6)

comment:1 by mrts, 6 years ago

Summary: Setting DATABASES['default']['TEST']['engine'] to SQLite does not cause Django to use an in-memory database if DATABASES['default']['NAME'] is givenSetting DATABASES['default']['TEST']['engine'] to SQLite does not cause Django to use an in-memory database as expected

comment:2 by mrts, 6 years ago

There is a workaround documented here:

https://stackoverflow.com/a/3098182/258772

But this is complex and fragile.

comment:3 by Tim Graham, 6 years ago

Component: UncategorizedTesting framework
Resolution: invalid
Status: newclosed
Type: UncategorizedBug

'ENGINE' isn't a supported option in 'TEST':

Aside from using a separate database, the test runner will otherwise use all of the same database settings you have in your settings file: ENGINE, USER, HOST, etc.

You should use a separate settings file when testing if you want to use a different database backend.

in reply to:  3 comment:4 by mrts, 6 years ago

Replying to Tim Graham:

'ENGINE' isn't a supported option in 'TEST':

Aside from using a separate database, the test runner will otherwise use all of the same database settings you have in your settings file: ENGINE, USER, HOST, etc.

You should use a separate settings file when testing if you want to use a different database backend.

Thanks for clarifying! This is not clear from the documentation section that you referred to. Should I submit a documentation patch?

comment:5 by Tim Graham, 6 years ago

I'm not sure if clarification is required. The sentence is clear to me and there's no documentation for a TEST['ENGINE'] setting.

comment:6 by mrts, 6 years ago

Alright, let's leave it as is then. Thanks for helping!

Note: See TracTickets for help on using tickets.
Back to Top