1616from py_pglite import PGliteConfig , PGliteManager
1717
1818
19- @pytest .fixture (scope = "session" )
20- def pglite_manager ():
21- """
22- 🎯 Base PGlite manager fixture
19+ # Removed pglite_manager fixture - let the Django backend handle PGlite lifecycle
20+ # This prevents conflicts with pytest-django's own database setup
2321
24- Provides fresh PGlite instance for each test.
25- Used by both Django and pytest-django patterns.
26- """
27- manager = PGliteManager (PGliteConfig ())
28- manager .start ()
29- manager .wait_for_ready ()
3022
31- try :
32- yield manager
33- finally :
34- manager .stop ()
23+ @pytest .fixture (autouse = True )
24+ def _enable_db_access (db ):
25+ """Enable Django DB access for every test in this directory.
26+
27+ This autouse fixture ensures all tests can access the database
28+ without needing explicit @pytest.mark.django_db or db fixture.
29+ """
30+ # Just importing the 'db' fixture is enough to enable database access
31+ pass
3532
3633
3734@pytest .fixture (autouse = True )
@@ -54,17 +51,13 @@ def setup_django_mail():
5451
5552
5653@pytest .fixture (scope = "function" )
57- def configured_django (pglite_manager ):
54+ def configured_django ():
5855 """
5956 🎯 Configured Django environment
6057
6158 Provides Django setup for both Django ORM and pytest-django testing.
62- This is the main abstraction point for Django + py-pglite .
59+ This works with the PGlite instance managed by the Django backend .
6360 """
64- # Get connection details from PGlite
65- conn_str = pglite_manager .config .get_connection_string ()
66- socket_dir = conn_str .split ("host=" )[1 ].split ("&" )[0 ].split ("#" )[0 ]
67-
6861 # Configure Django if not already configured
6962 if not settings .configured :
7063 settings .configure (
@@ -74,7 +67,7 @@ def configured_django(pglite_manager):
7467 "NAME" : "postgres" ,
7568 "USER" : "postgres" ,
7669 "PASSWORD" : "postgres" ,
77- "HOST" : socket_dir ,
70+ "HOST" : "" , # Let backend handle socket path
7871 "PORT" : "" ,
7972 "OPTIONS" : {},
8073 }
@@ -96,11 +89,11 @@ def configured_django(pglite_manager):
9689 if not hasattr (mail , "outbox" ):
9790 mail .outbox = []
9891 else :
99- # Update existing configuration with new PGlite connection
92+ # Ensure we're using the py-pglite backend
10093 settings .DATABASES ["default" ].update (
10194 {
10295 "ENGINE" : "py_pglite.django.backend" ,
103- "HOST" : socket_dir ,
96+ "HOST" : "" , # Let backend handle socket path
10497 }
10598 )
10699
0 commit comments