summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2021-04-12 08:41:39 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-12 08:54:03 +0200
commit71a936f9d84864a1420ce3ecc3de4a4908dff1e8 (patch)
tree4774c1f9e857ca72f0481cf5b242a6eaca415112
parente4430f22c8e3d29ce5d9d0263fba57121938d06d (diff)
Refs #32416 -- Added LiveServerTestCase._make_connections_override() hook.
-rw-r--r--django/test/testcases.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 92f566b7b0..6ae27243b1 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1553,21 +1553,28 @@ class LiveServerTestCase(TransactionTestCase):
return cls.host
@classmethod
- def setUpClass(cls):
- super().setUpClass()
+ def _make_connections_override(cls):
connections_override = {}
for conn in connections.all():
# If using in-memory sqlite databases, pass the connections to
# the server thread.
if conn.vendor == 'sqlite' and conn.is_in_memory_db():
- # Explicitly enable thread-shareability for this connection
- conn.inc_thread_sharing()
connections_override[conn.alias] = conn
+ return connections_override
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
cls._live_server_modified_settings = modify_settings(
ALLOWED_HOSTS={'append': cls.allowed_host},
)
cls._live_server_modified_settings.enable()
+
+ connections_override = cls._make_connections_override()
+ for conn in connections_override.values():
+ # Explicitly enable thread-shareability for this connection.
+ conn.inc_thread_sharing()
+
cls.server_thread = cls._create_server_thread(connections_override)
cls.server_thread.daemon = True
cls.server_thread.start()