Search code examples
djangopostgresqlpsycopg2django-tests

Can't test django 1.7 app


I am running Django==1.7 with psycopg2==2.5.4 and I'm unable to run any of my tests.

When I attempt to run any of my django test cases (by running ./manage test <app>), I get the following error:

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

My database settings are very basic:

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

The user I am using (system is Ubuntu 14.04) has full postgres admin privileges and I can successfully manually create / drop the db:

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

My model migrations appear to be fine- I can drop the db, successfully run the migrations and my web app functions fine- I just can't run the tests.

I have another django 1.7 project on this same machine, using the same basic postgres database setup, running as the same user and the tests run fine.

Any ideas what could be preventing tests from running?


Solution

  • This is caused by my project including the djorm-ext-pool app. Removing djorm_pool from INSTALLED_APPS resolves the issue.

    The app must be starting a transaction before the django test runner creates the test database.