【问题标题】:Can't test django 1.7 app无法测试 django 1.7 应用程序
【发布时间】:2014-11-22 11:32:45
【问题描述】:

我正在运行 Django==1.7psycopg2==2.5.4,但我无法运行任何测试。

当我尝试运行我的任何 django 测试用例(通过运行 ./manage test <app>)时,我收到以下错误:

Creating test database for alias 'default'...
Got an error creating the test database: CREATE DATABASE cannot run inside a transaction block
...
Destroying old test database 'default'...
Got an error recreating the test database: current transaction is aborted, commands ignored until end of transaction block

我的数据库设置非常基础:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
    }
}

我使用的用户(系统是 Ubuntu 14.04)拥有完整的 postgres 管理员权限,我可以成功手动创建/删除数据库:

(env)user@host:~$ createdb test_mydb
(env)user@host:~$ dropdb test_mydb
(env)user@host:~$ 

我的模型迁移似乎很好 - 我可以删除数据库,成功运行迁移并且我的 Web 应用程序功能正常 - 我只是无法运行测试。

我在同一台机器上有另一个 django 1.7 项目,使用相同的基本 postgres 数据库设置,以相同的用户身份运行并且测试运行良好。

有什么想法可以阻止测试运行吗?

【问题讨论】:

  • 通过排除过程,我确定这与djorm-ext-pool 应用程序有关。当我从 INSTALLED_APPS 中删除 djorm_pool 时,我不再收到错误消息。
  • 这适合自我回答,做得很好。它一定是太早建立交易了。

标签: django postgresql psycopg2 django-tests


【解决方案1】:

这是由我的项目引起的,包括djorm-ext-pool 应用程序。从 INSTALLED_APPS 中删除 djorm_pool 可以解决此问题。

应用程序必须在 django 测试运行程序创建测试数据库之前启动事务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    相关资源
    最近更新 更多