Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.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 Pytest并行运行-数据库不存在_Python_Django_Pytest - Fatal编程技术网

Python Django Pytest并行运行-数据库不存在

Python Django Pytest并行运行-数据库不存在,python,django,pytest,Python,Django,Pytest,我正在使用pytest运行django测试,并试图通过并行运行来加快测试速度。我尝试使用环境变量PYTEST\u XDIST\u WORKER修改数据库名称,但我的测试仍然无法访问数据库 我需要如何在django配置中设置数据库设置,以便创建和使用并行数据库 db_suffix = env.str("PYTEST_XDIST_WORKER", "") DATABASES["default"]["NAME"] = f&

我正在使用pytest运行django测试,并试图通过并行运行来加快测试速度。我尝试使用环境变量
PYTEST\u XDIST\u WORKER
修改数据库名称,但我的测试仍然无法访问数据库

我需要如何在django配置中设置数据库设置,以便创建和使用并行数据库

db_suffix = env.str("PYTEST_XDIST_WORKER", "")
DATABASES["default"]["NAME"] = f"""{DATABASES["default"]["NAME"]}_{db_suffix}"""
pytest.ini

[pytest]
addopts = --ds=config.settings.test --create-db
python_files = tests.py test_*.py
norecursedirs = node_modules
env_files=
    .env.tests
运行测试的命令:
pytest-n4

错误:
数据库“auto\u tests\u gw0”不存在