@@ -8,7 +8,7 @@ class LiveServer:
8
8
The ``live_server`` fixture handles creation and stopping.
9
9
"""
10
10
11
- def __init__ (self , addr : str ) -> None :
11
+ def __init__ (self , addr : str , * , start : bool = True ) -> None :
12
12
from django .db import connections
13
13
from django .test .testcases import LiveServerThread
14
14
from django .test .utils import modify_settings
@@ -20,8 +20,6 @@ def __init__(self, addr: str) -> None:
20
20
# If using in-memory sqlite databases, pass the connections to
21
21
# the server thread.
22
22
if conn .vendor == "sqlite" and conn .is_in_memory_db ():
23
- # Explicitly enable thread-shareability for this connection.
24
- conn .inc_thread_sharing ()
25
23
connections_override [conn .alias ] = conn
26
24
27
25
liveserver_kwargs ["connections_override" ] = connections_override
@@ -51,6 +49,16 @@ def __init__(self, addr: str) -> None:
51
49
# `_live_server_helper`.
52
50
53
51
self .thread .daemon = True
52
+
53
+ if start :
54
+ self .start ()
55
+
56
+ def start (self ) -> None :
57
+ """Start the server"""
58
+ for conn in self .thread .connections_override .values ():
59
+ # Explicitly enable thread-shareability for this connection.
60
+ conn .inc_thread_sharing ()
61
+
54
62
self .thread .start ()
55
63
self .thread .is_ready .wait ()
56
64
0 commit comments