diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index ce1da6d..7855f26 100644
a
|
b
|
from django.conf import settings
|
5 | 5 | |
6 | 6 | # The prefix to put on the default database name when creating |
7 | 7 | # the test database. |
| 8 | from django.db.utils import load_backend |
| 9 | |
8 | 10 | TEST_DATABASE_PREFIX = 'test_' |
9 | 11 | |
10 | 12 | class BaseDatabaseCreation(object): |
… |
… |
class BaseDatabaseCreation(object):
|
320 | 322 | if verbosity >= 2: |
321 | 323 | test_db_repr = " ('%s')" % test_database_name |
322 | 324 | print "Destroying test database for alias '%s'%s..." % (self.connection.alias, test_db_repr) |
323 | | self.connection.settings_dict['NAME'] = old_database_name |
324 | 325 | |
| 326 | # Temporarily use a new thread-local connection and a thread-local |
| 327 | # copy of the settings dict. This prevents the production database from |
| 328 | # being exposed to potential child threads while the test database is |
| 329 | # being destroyed. Refs #10868. |
| 330 | original_connection = self.connection |
| 331 | settings_dict = original_connection.settings_dict.copy() |
| 332 | settings_dict['NAME'] = old_database_name |
| 333 | backend = load_backend(settings_dict['ENGINE']) |
| 334 | self.connection = backend.DatabaseWrapper( |
| 335 | settings_dict, |
| 336 | alias='__destroy_test_db__', |
| 337 | allow_thread_sharing=False) |
325 | 338 | self._destroy_test_db(test_database_name, verbosity) |
| 339 | self.connection = original_connection |
326 | 340 | |
327 | 341 | def _destroy_test_db(self, test_database_name, verbosity): |
328 | 342 | "Internal implementation - remove the test db tables." |
diff --git a/django/test/simple.py b/django/test/simple.py
index 1534011..73aeb2c 100644
a
|
b
|
class DjangoTestSuiteRunner(object):
|
312 | 312 | return unittest.TextTestRunner(verbosity=self.verbosity, failfast=self.failfast).run(suite) |
313 | 313 | |
314 | 314 | def teardown_databases(self, old_config, **kwargs): |
315 | | from django.db import connections |
| 315 | """ |
| 316 | Destroys all the non-mirror databases |
| 317 | """ |
316 | 318 | old_names, mirrors = old_config |
317 | | # Point all the mirrors back to the originals |
318 | | for alias, old_name in mirrors: |
319 | | connections[alias].settings_dict['NAME'] = old_name |
320 | | # Destroy all the non-mirror databases |
321 | 319 | for connection, old_name, destroy in old_names: |
322 | 320 | if destroy: |
323 | 321 | connection.creation.destroy_test_db(old_name, self.verbosity) |
324 | | else: |
325 | | connection.settings_dict['NAME'] = old_name |
326 | 322 | |
327 | 323 | def teardown_test_environment(self, **kwargs): |
328 | 324 | unittest.removeHandler() |