From 71a936f9d84864a1420ce3ecc3de4a4908dff1e8 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Mon, 12 Apr 2021 08:41:39 +0200 Subject: [PATCH] Refs #32416 -- Added LiveServerTestCase._make_connections_override() hook. --- django/test/testcases.py | 15 +++++++++++---- 1 file 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()