summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2010-11-30 22:16:53 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2010-11-30 22:16:53 +0000
commit5eb62e1d942f194bd418c8e51da17605a08dc601 (patch)
treee56dc7993dc12b932972b03f92338906c0fc752c
parentf1d4f713e563e8e352b870fe30426579dcc7b5ce (diff)
[1.2.X] Ensured that the test suite creates the default DB before any others.
Refs #14799. Backport of [14756], and see the note there for a caveat. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14757 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/test/simple.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/django/test/simple.py b/django/test/simple.py
index 2b839c3ee1..76a5b735ed 100644
--- a/django/test/simple.py
+++ b/django/test/simple.py
@@ -254,7 +254,7 @@ class DjangoTestSuiteRunner(object):
return reorder_suite(suite, (TestCase,))
def setup_databases(self, **kwargs):
- from django.db import connections
+ from django.db import connections, DEFAULT_DB_ALIAS
# First pass -- work out which databases actually need to be created,
# and which ones are test mirrors or duplicate entries in DATABASES
@@ -276,11 +276,21 @@ class DjangoTestSuiteRunner(object):
connection.settings_dict['ENGINE'],
connection.settings_dict['NAME'],
), []).append(alias)
-
- # Second pass -- actually create the databases.
+
+ # Re-order the list of databases to create, making sure the default
+ # database is first. Otherwise, creation order is semi-random (i.e.
+ # dict ordering dependent).
+ dbs_to_create = []
+ for dbinfo, aliases in test_databases.items():
+ if DEFAULT_DB_ALIAS in aliases:
+ dbs_to_create.insert(0, (dbinfo, aliases))
+ else:
+ dbs_to_create.append((dbinfo, aliases))
+
+ # Final pass -- actually create the databases.
old_names = []
mirrors = []
- for (host, port, engine, db_name), aliases in test_databases.items():
+ for (host, port, engine, db_name), aliases in dbs_to_create:
# Actually create the database for the first connection
connection = connections[aliases[0]]
old_names.append((connection, db_name, True))