Skip to content

Commit 904a995

Browse files
committed
live_server_helper: improve sqlite in-memory check
This will make it so it's covered by our tests.
1 parent f64b252 commit 904a995

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

pytest_django/live_server_helper.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ def __init__(self, addr: str) -> None:
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
22+
if conn.vendor == 'sqlite' and conn.is_in_memory_db():
23+
# Explicitly enable thread-shareability for this connection.
2724
conn.inc_thread_sharing()
2825
connections_override[conn.alias] = conn
2926

pytest_django_test/db_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
if _settings["ENGINE"] == "django.db.backends.sqlite3" and TEST_DB_NAME is None:
1717
TEST_DB_NAME = ":memory:"
18+
SECOND_DB_NAME = ":memory:"
19+
SECOND_TEST_DB_NAME = ":memory:"
1820
else:
1921
DB_NAME += "_inner"
2022

@@ -25,8 +27,8 @@
2527
# An explicit test db name was given, is that as the base name
2628
TEST_DB_NAME = "{}_inner".format(TEST_DB_NAME)
2729

28-
SECOND_DB_NAME = DB_NAME + '_second' if DB_NAME is not None else None
29-
SECOND_TEST_DB_NAME = TEST_DB_NAME + '_second' if DB_NAME is not None else None
30+
SECOND_DB_NAME = DB_NAME + '_second' if DB_NAME is not None else None
31+
SECOND_TEST_DB_NAME = TEST_DB_NAME + '_second' if DB_NAME is not None else None
3032

3133

3234
def get_db_engine():

pytest_django_test/settings_sqlite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
DATABASES = {
55
"default": {
66
"ENGINE": "django.db.backends.sqlite3",
7-
"NAME": "/should_not_be_accessed",
7+
"NAME": ":memory:",
88
},
99
"replica": {
1010
"ENGINE": "django.db.backends.sqlite3",
11-
"NAME": "/should_not_be_accessed",
11+
"NAME": ":memory:",
1212
"TEST": {
1313
"MIRROR": "default",
1414
},
1515
},
1616
"second": {
1717
"ENGINE": "django.db.backends.sqlite3",
18-
"NAME": "/should_not_be_accessed",
18+
"NAME": ":memory:",
1919
},
2020
}

pytest_django_test/settings_sqlite_file.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"default": {
1616
"ENGINE": "django.db.backends.sqlite3",
1717
"NAME": "/pytest_django_tests_default",
18-
"TEST": {"NAME": _filename_default},
18+
"TEST": {
19+
"NAME": _filename_default,
20+
},
1921
},
2022
"replica": {
2123
"ENGINE": "django.db.backends.sqlite3",
@@ -28,6 +30,8 @@
2830
"second": {
2931
"ENGINE": "django.db.backends.sqlite3",
3032
"NAME": "/pytest_django_tests_second",
31-
"TEST": {"NAME": _filename_second},
33+
"TEST": {
34+
"NAME": _filename_second,
35+
},
3236
},
3337
}

0 commit comments

Comments
 (0)