summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2026-04-16 05:28:19 -0400
committerGitHub <noreply@github.com>2026-04-16 11:28:19 +0200
commit82a2465f71a1f5cbfe3811952c0d07482dea71c6 (patch)
tree8e7fa97a43cb858dff278b87acb7187646c34d51 /django
parent86cea4145dcd870231ea81f3cfe78fcbe02dbae4 (diff)
Added DatabaseFeatures.disallowed_simple_test_case_connection_methods.
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/base/features.py9
-rw-r--r--django/test/testcases.py18
2 files changed, 18 insertions, 9 deletions
diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py
index 466f8199bf..0d9178dae8 100644
--- a/django/db/backends/base/features.py
+++ b/django/db/backends/base/features.py
@@ -431,6 +431,15 @@ class BaseDatabaseFeatures:
# that should be skipped for this database.
django_test_skips = {}
+ # DatabaseWrapper methods that should raise an error if accessed in
+ # django.test.SimpleTestCase.
+ disallowed_simple_test_case_connection_methods = [
+ ("connect", "connections"),
+ ("temporary_connection", "connections"),
+ ("cursor", "queries"),
+ ("chunked_cursor", "queries"),
+ ]
+
supports_uuid4_function = False
supports_uuid7_function = False
supports_uuid7_function_shift = False
diff --git a/django/test/testcases.py b/django/test/testcases.py
index b31e70d9d1..f866a33963 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -189,7 +189,7 @@ class _DatabaseFailure:
self.wrapped = wrapped
self.message = message
- def __call__(self):
+ def __call__(self, *args, **kwargs):
raise DatabaseOperationForbidden(self.message)
@@ -209,12 +209,6 @@ class SimpleTestCase(unittest.TestCase):
"proper test isolation or add %(alias)r to %(test)s.databases to silence "
"this failure."
)
- _disallowed_connection_methods = [
- ("connect", "connections"),
- ("temporary_connection", "connections"),
- ("cursor", "queries"),
- ("chunked_cursor", "queries"),
- ]
@classmethod
def setUpClass(cls):
@@ -254,7 +248,10 @@ class SimpleTestCase(unittest.TestCase):
if alias in cls.databases:
continue
connection = connections[alias]
- for name, operation in cls._disallowed_connection_methods:
+ disallowed_methods = (
+ connection.features.disallowed_simple_test_case_connection_methods
+ )
+ for name, operation in disallowed_methods:
message = cls._disallowed_database_msg % {
"test": "%s.%s" % (cls.__module__, cls.__qualname__),
"alias": alias,
@@ -276,7 +273,10 @@ class SimpleTestCase(unittest.TestCase):
if alias in cls.databases:
continue
connection = connections[alias]
- for name, _ in cls._disallowed_connection_methods:
+ disallowed_methods = (
+ connection.features.disallowed_simple_test_case_connection_methods
+ )
+ for name, _ in disallowed_methods:
method = getattr(connection, name)
setattr(connection, name, method.wrapped)