Skip to content

Commit 6b251d0

Browse files
committed
fix tests
1 parent a854ea9 commit 6b251d0

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

examples/testing-patterns/django/__init__.py

Whitespace-only changes.

examples/testing-patterns/django/conftest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def pglite_manager():
2626
"""
2727
manager = PGliteManager(PGliteConfig())
2828
manager.start()
29+
manager.wait_for_ready()
2930

3031
try:
3132
yield manager
@@ -69,13 +70,13 @@ def configured_django(pglite_manager):
6970
settings.configure(
7071
DATABASES={
7172
"default": {
72-
"ENGINE": "django.db.backends.postgresql",
73+
"ENGINE": "py_pglite.django.backend",
7374
"NAME": "postgres",
7475
"USER": "postgres",
7576
"PASSWORD": "postgres",
7677
"HOST": socket_dir,
7778
"PORT": "",
78-
"OPTIONS": {"connect_timeout": 10},
79+
"OPTIONS": {},
7980
}
8081
},
8182
INSTALLED_APPS=[
@@ -96,7 +97,12 @@ def configured_django(pglite_manager):
9697
mail.outbox = []
9798
else:
9899
# Update existing configuration with new PGlite connection
99-
settings.DATABASES["default"]["HOST"] = socket_dir
100+
settings.DATABASES["default"].update(
101+
{
102+
"ENGINE": "py_pglite.django.backend",
103+
"HOST": socket_dir,
104+
}
105+
)
100106

101107
# Reset connections to use new database
102108
from django.db import connections

examples/testing-patterns/django/test_pytest_django.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,16 @@
1616
For basic Django testing without pytest-django, see test_django_quickstart.py
1717
"""
1818

19-
import os
20-
2119
import pytest
2220

23-
from django.conf import settings
2421
from django.db import connection, models
2522
from django.test import TestCase
2623

27-
# Configure Django settings for pytest-django
28-
os.environ.setdefault(
29-
"DJANGO_SETTINGS_MODULE", "examples.testing-patterns.django.settings"
30-
)
31-
3224
# pytest-django specific markers
3325
pytestmark = pytest.mark.django_db # Standard pytest-django marker
3426

3527

36-
# Ensure Django is configured before running tests
37-
def pytest_configure():
38-
"""Configure Django settings for pytest-django."""
39-
if not settings.configured:
40-
settings.configure(
41-
DATABASES={
42-
"default": {
43-
"ENGINE": "py_pglite.django.backend",
44-
"NAME": "test_pglite_db",
45-
}
46-
},
47-
INSTALLED_APPS=[
48-
"django.contrib.contenttypes",
49-
"django.contrib.auth",
50-
],
51-
USE_TZ=True,
52-
)
28+
# Ensure Django is configured via external fixtures or plugin
5329

5430

5531
def test_with_django_db_marker(configured_django):

py_pglite/django/backend/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def _create_test_db(
5555
# Start PGlite if not already running
5656
if not manager.is_running():
5757
manager.start()
58-
# Give the socket a moment to be fully ready
59-
time.sleep(1)
58+
# Wait until PGlite is ready to accept connections
59+
manager.wait_for_ready()
6060

6161
# Update connection settings to use PGlite
6262
self._update_connection_settings(test_database_name, manager)
@@ -193,9 +193,7 @@ def _update_connection_settings(self, db_name: str, manager: PGliteManager) -> N
193193
"NAME": "postgres", # PGlite only has 'postgres' database
194194
"USER": "postgres",
195195
"PASSWORD": "postgres",
196-
"OPTIONS": {
197-
"options": f"-c search_path={db_name},public" # Use schema for isolation
198-
},
196+
"OPTIONS": {},
199197
}
200198
)
201199

@@ -262,7 +260,7 @@ def get_new_connection(self, conn_params: dict[str, Any]) -> Any:
262260
"dbname": "postgres", # Always use 'postgres' in PGlite
263261
"user": "postgres",
264262
"password": "postgres",
265-
"options": f"-c search_path={db_name},public", # Schema isolation
263+
# PGlite may not support session search_path options reliably
266264
}
267265
)
268266

0 commit comments

Comments
 (0)