In order to pass the unit tests running on a fresh install of django trunk (1.4c1), it is necessary to add in a 'dummy' other
database in settings.py, like this:-
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydb', # Or path to database file if using sqlite3.
'USER': 'myuser', # Not used with sqlite3.
'PASSWORD': 'mypassword', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
},
# dummy sqlite3 database created to pass django's builtin unit tests
'other': {
'ENGINE': 'django.db.backends.sqlite3'
}
}
Why is that so and what is the purpose of this "ensure_defaults" function in django/db/utils.py's ConnectionHandler
class?
Just curious to understand django at a deeper level...
Django 1.4 adds a new subclass of TestCase
called SimpleTestCase
, that allows you to run tests that don't need a database connection. My guess is that django.db.backends.dummy
is being used as a sort of default database in this scenario, as ensure_defaults
sets this as the database, if no database is specified.
However, as to why you have to add an additional database engine to make your tests pass, I can't say. There's absolutely no mention of this in the release notes for 1.4, and it doesn't sound right like something Django would require. It's possible this may be a bug (1.4 is only in release candidate stage right now, so it's certainly open to bugs), but without additional confirmation, there's no way to know.
I'm not in a position to test it myself right now, but I will try later today.