From 00a1d42bf0d83ba4b329271433eb5e3fd0f704fe Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 10 Dec 2020 18:48:07 +0100 Subject: [PATCH] Fixed isolation of test_runner.EmptyDefaultDatabaseTest. This fixes test_runner.test_debug_sql.TestDebugSQL. test_setupclass_exception when run in reverse. --- tests/test_runner/tests.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index e12ea3b11a..07c7836708 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -11,7 +11,7 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command from django.core.management.base import SystemCheckError -from django.test import TransactionTestCase, skipUnlessDBFeature, testcases +from django.test import TransactionTestCase, skipUnlessDBFeature from django.test.runner import DiscoverRunner from django.test.testcases import connections_support_transactions from django.test.utils import captured_stderr, dependency_ordered @@ -413,10 +413,11 @@ class EmptyDefaultDatabaseTest(unittest.TestCase): An empty default database in settings does not raise an ImproperlyConfigured error when running a unit test that does not use a database. """ - testcases.connections = db.ConnectionHandler({'default': {}}) - connection = testcases.connections[db.utils.DEFAULT_DB_ALIAS] - self.assertEqual(connection.settings_dict['ENGINE'], 'django.db.backends.dummy') - connections_support_transactions() + tested_connections = db.ConnectionHandler({'default': {}}) + with mock.patch('django.db.connections', new=tested_connections): + connection = tested_connections[db.utils.DEFAULT_DB_ALIAS] + self.assertEqual(connection.settings_dict['ENGINE'], 'django.db.backends.dummy') + connections_support_transactions() class RunTestsExceptionHandlingTests(unittest.TestCase):