Skip to content

Commit 9d110ff

Browse files
committed
live_server: fix in-memory DB detection, dj 2.2 compat
Fixes pytest-dev#783.
1 parent 1625ece commit 9d110ff

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pytest_django/live_server_helper.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ def __init__(self, addr):
1919
for conn in connections.all():
2020
# If using in-memory sqlite databases, pass the connections to
2121
# the server thread.
22-
if (
23-
conn.settings_dict["ENGINE"] == "django.db.backends.sqlite3"
24-
and conn.settings_dict["NAME"] == ":memory:"
25-
):
26-
# Explicitly enable thread-shareability for this connection
27-
conn.allow_thread_sharing = True
28-
connections_override[conn.alias] = conn
22+
if conn.settings_dict["ENGINE"] == "django.db.backends.sqlite3":
23+
test_dbname = conn.settings_dict['TEST']['NAME'] or ':memory:'
24+
if test_dbname == ":memory:":
25+
# Explicitly enable thread-shareability for this connection
26+
if django.VERSION >= (2, 2):
27+
conn.inc_thread_sharing()
28+
else:
29+
conn.allow_thread_sharing = True
30+
connections_override[conn.alias] = conn
2931

3032
liveserver_kwargs = {"connections_override": connections_override}
3133
from django.conf import settings

0 commit comments

Comments
 (0)