Opened 6 years ago

Last modified 4 years ago

#25504 new Bug

Django test teardown fails when there is no default database

Reported by: Sjoerd Langkemper Owned by:
Component: Testing framework Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When running a Django TestCase with an empty dict as default database, I get an error. This is similar to #24394, but happens at teardown of the test.

I installed Django 1.9a1, created a new project using django-admin startproject bug. I edited my to read this:

    'default': {},
    'other': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

And I added an empty testcase that uses the Django TestCase class like this:

from django.test.testcases import TestCase

class Test(TestCase):
    def test_nothing(self):

Then, when I do ./manage test I get the following stacktrace:

Traceback (most recent call last):
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/test/", line 217, in __call__
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/test/", line 919, in _post_teardown
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/test/", line 1072, in _fixture_teardown
    return super(TestCase, self)._fixture_teardown()
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/test/", line 955, in _fixture_teardown
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/core/management/", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/core/management/", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/core/management/commands/", line 49, in handle
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/core/management/", line 15, in sql_flush
    tables = connection.introspection.django_table_names(only_existing=True, include_views=False)
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/db/backends/base/", line 86, in django_table_names
    existing_tables = self.table_names(include_views=include_views)
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/db/backends/base/", line 56, in table_names
    with self.connection.cursor() as cursor:
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/db/backends/base/", line 233, in cursor
    cursor = self.make_cursor(self._cursor())
  File "/home/sjoerd/.virtualenvs/b24394/local/lib/python2.7/site-packages/django/db/backends/dummy/", line 21, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Change History (6)

comment:1 Changed 6 years ago by Tim Graham

Component: UncategorizedTesting framework
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 6 years ago by mihaicc

Owner: changed from nobody to mihaicc
Status: newassigned

comment:3 Changed 6 years ago by mihaicc

I didn't manage to finish this ticket.

Progress so far:

  • have 2 tests (one broader and one narrower to the exception)
  • found out this happens for fixtures setup as well
  • debated two solutions with Michael Manfre and Tim and will follow soon with a pull request

comment:4 Changed 6 years ago by Tim Graham

Version: 1.9a11.9

comment:5 Changed 5 years ago by Tim Graham

mihaicc, can you share a link to your work so others could use it as a starting point if you're unable to finish it?

comment:6 Changed 4 years ago by mihaicc

Owner: mihaicc deleted
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top