You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See also [examples/test_fastapi_auth_example.py](examples/test_fastapi_auth_example.py) for an example of how to use py-pglite with FastAPI e2e test that includes authentication.
For multiple database connections, use **multiple sessions with the same engine** rather than multiple engines:
418
-
419
-
```python
420
-
# ✅ Recommended: Multiple sessions with same engine
421
-
with PGliteManager() as manager:
422
-
engine = manager.get_engine()
423
-
424
-
# Multiple sessions work perfectly
425
-
session1 = Session(engine)
426
-
session2 = Session(engine)
427
-
session3 = Session(engine)
428
-
429
-
# ❌ Not recommended: Multiple engines from same manager
430
-
with PGliteManager() as manager:
431
-
engine1 = manager.get_engine() # Can cause connection conflicts
432
-
engine2 = manager.get_engine() # when used simultaneously
433
-
```
434
-
435
-
**Why?** Creating multiple SQLAlchemy engines from the same PGlite manager can cause connection pool conflicts since they all connect to the same Unix socket.
436
-
437
-
### Performance Tips
438
-
439
-
- Use `pglite_session` fixture for automatic cleanup between tests
440
-
- Use `pglite_engine` fixture when you need direct engine access
441
-
- Use utility functions for efficient database operations
442
-
- Consider custom configurations for specific test requirements
443
-
444
-
### Testing Patterns
445
-
446
-
```python
447
-
# Pattern 1: Simple CRUD testing
448
-
deftest_user_crud(pglite_session):
449
-
# Create
450
-
user = User(name="Test", email="test@example.com")
0 commit comments