Search code examples
pythondjangodjango-unittest

Django Unit Testing stucks with an E


I'm experiencing a strange error in Djangos Unit Testing Framework. It worked before, but out of the blue, the tests do not work any longer.

The framework puts out:

python manage.py test
Creating test database for alias 'default'...
................................................................
................................................................
................................................................
................................................................
......................s.........................................
E

The E is the last thing that is, there, then everything freezes.

It's the same (without the run tests) when I just try to test a single app. If I do run a test directly after the crash I get:

python manage.py test someapp
Creating test database for alias 'default'...
Got an error creating the test database: database "test_pybackend" already exists

Type 'yes' if you would like to try deleting the test database 'test_pybackend', 
or 'no' to cancel: yes
Destroying old test database 'default'...
E

The obvious problem is, that the test database never gets destroyed.

What may me the reason - and what may be a solution?


Solution

  • E means that one of your tests causes an error when it runs. It looks like that error is somehow bad enough to stop the whole testing framework running, resulting in the test database not getting deleted.

    Do you get the E when you test every app in the project individually, or only for a certain app?

    You’ll want to figure out which test contains the error. You can run individual test case classes like this:

    python manage.py test someapp.TestCaseClassName
    

    And individual test methods like this:

    python manage.py test someapp.TestCaseClassName.test_method
    

    (See https://docs.djangoproject.com/en/dev/topics/testing/#running-tests)