Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何设置django在unittest期间不使用内存中的数据库?_Python_Django_Unit Testing_Sqlite - Fatal编程技术网

Python 如何设置django在unittest期间不使用内存中的数据库?

Python 如何设置django在unittest期间不使用内存中的数据库?,python,django,unit-testing,sqlite,Python,Django,Unit Testing,Sqlite,django在内存中设置一个数据库,用于测试所选的数据库引擎是否为sqlite3。但是,我需要数据库位于文件系统上。如何更改设置以实现这一点?根据: 默认情况下,测试数据库通过在test_uuu之前加上前缀来获取其名称 数据库中定义的数据库的名称设置值。 使用SQLite数据库引擎时,默认情况下测试将使用 内存数据库(即,数据库将在内存中创建, 完全绕过文件系统!)如果要使用不同的 数据库名称,在测试字典中为任何给定的 数据库中的数据库 在字典中指定名称键: DATABASES = {

django在内存中设置一个数据库,用于测试所选的数据库引擎是否为sqlite3。但是,我需要数据库位于文件系统上。如何更改设置以实现这一点?

根据:

默认情况下,测试数据库通过在test_uuu之前加上前缀来获取其名称 数据库中定义的数据库的名称设置值。 使用SQLite数据库引擎时,默认情况下测试将使用 内存数据库(即,数据库将在内存中创建, 完全绕过文件系统!)如果要使用不同的 数据库名称,在测试字典中为任何给定的 数据库中的数据库

在字典中指定
名称
键:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        ...
        'TEST': {
            'NAME': '/path/to/the/db/file'
        }
    }
}
请注意,对于Django 1.6及以下版本,应改为设置
TEST\u NAME

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

为什么需要文件系统上的db?我不建议对任何严重的问题使用SQLite。