summaryrefslogtreecommitdiff
path: root/tests/backends
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2026-01-03 13:42:02 -0500
committerGitHub <noreply@github.com>2026-01-03 19:42:02 +0100
commit3201a895cba335000827b28768a7b7105c81b415 (patch)
tree5d87531fb661f22133d37aee812dc988f50d5295 /tests/backends
parentd6ae2ed868e43671afc4d433c3d8f4d27f7eb555 (diff)
Added DatabaseCreation.destroy_test_db_connection_close_method hook.
Diffstat (limited to 'tests/backends')
-rw-r--r--tests/backends/base/test_creation.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/tests/backends/base/test_creation.py b/tests/backends/base/test_creation.py
index 202d8e1b40..2542407f0b 100644
--- a/tests/backends/base/test_creation.py
+++ b/tests/backends/base/test_creation.py
@@ -67,6 +67,13 @@ class TestDbSignatureTests(SimpleTestCase):
class TestDbCreationTests(SimpleTestCase):
available_apps = ["backends.base.app_unmigrated"]
+ @staticmethod
+ def patch_close_connection(creation):
+ # If DatabaseCreation.destroy_test_db() closes the database connection,
+ # that behavior must be disabled to prevent each test from crashing.
+ if close_method_name := creation.destroy_test_db_connection_close_method:
+ setattr(creation.connection, close_method_name, mock.Mock())
+
@mock.patch("django.db.migrations.executor.MigrationExecutor.migrate")
def test_migrate_test_setting_false(
self, mocked_migrate, mocked_sync_apps, *mocked_objects
@@ -74,9 +81,7 @@ class TestDbCreationTests(SimpleTestCase):
test_connection = get_connection_copy()
test_connection.settings_dict["TEST"]["MIGRATE"] = False
creation = test_connection.creation_class(test_connection)
- if connection.vendor == "oracle":
- # Don't close connection on Oracle.
- creation.connection.close = mock.Mock()
+ self.patch_close_connection(creation)
old_database_name = test_connection.settings_dict["NAME"]
try:
with mock.patch.object(creation, "_create_test_db"):
@@ -104,9 +109,7 @@ class TestDbCreationTests(SimpleTestCase):
test_connection = get_connection_copy()
test_connection.settings_dict["TEST"]["MIGRATE"] = False
creation = test_connection.creation_class(test_connection)
- if connection.vendor == "oracle":
- # Don't close connection on Oracle.
- creation.connection.close = mock.Mock()
+ self.patch_close_connection(creation)
old_database_name = test_connection.settings_dict["NAME"]
try:
with mock.patch.object(creation, "_create_test_db"):
@@ -128,9 +131,7 @@ class TestDbCreationTests(SimpleTestCase):
test_connection = get_connection_copy()
test_connection.settings_dict["TEST"]["MIGRATE"] = True
creation = test_connection.creation_class(test_connection)
- if connection.vendor == "oracle":
- # Don't close connection on Oracle.
- creation.connection.close = mock.Mock()
+ self.patch_close_connection(creation)
old_database_name = test_connection.settings_dict["NAME"]
try:
with mock.patch.object(creation, "_create_test_db"):
@@ -158,9 +159,7 @@ class TestDbCreationTests(SimpleTestCase):
"""
test_connection = get_connection_copy()
creation = test_connection.creation_class(test_connection)
- if connection.vendor == "oracle":
- # Don't close connection on Oracle.
- creation.connection.close = mock.Mock()
+ self.patch_close_connection(creation)
old_database_name = test_connection.settings_dict["NAME"]
try:
with mock.patch.object(creation, "_create_test_db"):
@@ -175,9 +174,7 @@ class TestDbCreationTests(SimpleTestCase):
def test_serialize_deprecation(self, serialize_db_to_string, *mocked_objects):
test_connection = get_connection_copy()
creation = test_connection.creation_class(test_connection)
- if connection.vendor == "oracle":
- # Don't close connection on Oracle.
- creation.connection.close = mock.Mock()
+ self.patch_close_connection(creation)
old_database_name = test_connection.settings_dict["NAME"]
msg = (
"DatabaseCreation.create_test_db(serialize) is deprecated. Call "