Django 并行测试不创建数据库表
Django parallel tests not creating database tables
我正在尝试 运行 使用以下命令并行测试 Django:
python manage.py test myproject.myapp.tests --parallel=4 --keepdb
但是,我收到如下错误:
...
File "/home/daniel/Envs/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "accounts_user" does not exist
LINE 1: INSERT INTO "accounts_user" ("password", "last_login", "is_s...
^
这意味着没有在 Postgres 测试数据库中创建表。根据需要,我创建了名为 test_myproject_1
、test_myproject_2
等的数据库,在 pgAdmin 中检查后,我发现这些表确实不存在。我的假设是当测试 运行.
时自动创建表格
当 运行 在单个线程上进行测试时,换句话说,当我不使用 --parallel
选项或当我使用 [=15] 时,我不会出现此类错误=],它使用 test_myproject
数据库。有谁知道问题可能出在哪里?
问题在于同时使用 --parallel
和 --keepdb
,其中备用测试数据库不会迁移到当前状态。 运行 --parallel
没有 --keepdb
将强制刷新测试数据库中的数据库模式。
(如果由于 permission denied to create database
而在没有 --keepdb
的情况下无法 运行,则需要检查您的数据库用户是否具有正确的权限。)
有an open issue #26822 and a partial patch aiming to fix this, but there hasn't been any activity for a while. Also see the discussion on Django-developers mailing list.
我正在尝试 运行 使用以下命令并行测试 Django:
python manage.py test myproject.myapp.tests --parallel=4 --keepdb
但是,我收到如下错误:
...
File "/home/daniel/Envs/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "accounts_user" does not exist
LINE 1: INSERT INTO "accounts_user" ("password", "last_login", "is_s...
^
这意味着没有在 Postgres 测试数据库中创建表。根据需要,我创建了名为 test_myproject_1
、test_myproject_2
等的数据库,在 pgAdmin 中检查后,我发现这些表确实不存在。我的假设是当测试 运行.
当 运行 在单个线程上进行测试时,换句话说,当我不使用 --parallel
选项或当我使用 [=15] 时,我不会出现此类错误=],它使用 test_myproject
数据库。有谁知道问题可能出在哪里?
问题在于同时使用 --parallel
和 --keepdb
,其中备用测试数据库不会迁移到当前状态。 运行 --parallel
没有 --keepdb
将强制刷新测试数据库中的数据库模式。
(如果由于 permission denied to create database
而在没有 --keepdb
的情况下无法 运行,则需要检查您的数据库用户是否具有正确的权限。)
有an open issue #26822 and a partial patch aiming to fix this, but there hasn't been any activity for a while. Also see the discussion on Django-developers mailing list.