Open vstepanov opened 12 years ago
Configuring the connection while creating a new database isn't very good solution, but it was implemented in the method django/db/backends/creation.py:BaseDatabaseCreation.create_test_db which we have overridden by _skip_create_test_db. So the name in the connection settings must be set in _skip_create_test_db.
To use non-existent DB!!
Your _NoseTestSuiteRunner.setupdatabases renamed DB name (added prefix test_ to original DB name) in connection's settings and calls _DjangoTestSuiteRunner.setupdatabases:
class NoseTestSuiteRunner(BasicNoseRunner):
def setup_databases(self):
...
connection.settings_dict['NAME'] = test_db_name
...
return super(NoseTestSuiteRunner, self).setup_databases()
Note: before calls _DjangoTestSuiteRunner.setupdatabases all connections (_connection.settingsdict['NAME']) are renamed to the test DBs names (added prefix test_ to the original DB name).
Since a database can have multiple connections(aliases) to it, so:
class DjangoTestSuiteRunner(object):
...
def setup_databases(self, **kwargs):
...
for alias in aliases[1:]:
connection = connections[alias]
if db_name:
old_names.append((connection, db_name, False))
connection.settings_dict['NAME'] = test_db_name
You should put back original database name to _connection.settingsdict['NAME'] before calling _DjangoTestSuiteRunner.setupdatabases.
In NoseTestSuiteRunner.setup_databases all connections are renamed to test db names (creation._get_test_db_name() returns test_ORIGINAL_DB_NAME) and call setup_databases of DjangoTestSuiteRunner, in which this name was again renamed to test_test_ORIGINAL_DB_NAME .
This problem manifests itself, when there are several connections (aliases) to one database, because DjangoTestSuiteRunner.setup_databases sets connection.settings_dict['NAME'] = test_db_name for aliases which are more than one to one database.
Versions: django==1.4 django_nose==1.1 database - mysql
these changes have fixed the issue.