简体   繁体   中英

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

django sets up a database in memory for testing if the database engine selected is sqlite3. However, I need the database to be on the filesystem. How can I change the settings to make this possible?

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 (ie, 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'
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM