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
The PR correctly consolidates duplicate fixtures and switches to a session-scoped engine for efficiency. Dependency bumps look clean. A few issues are worth addressing:
Issues Found
1. Multiple long-lived sessions held open during test execution — tests/integration/conftest.py:34–108
admin_user, regular_user, and superuser_user all yield while inside async with test_db() as session:. This keeps a DB connection checked out from the pool for the entire test duration. When all three are injected into the same test (e.g. rbac_audit_client), three sessions are simultaneously open alongside any sessions created by the test body itself.
SQLite serializes writes, so this won't corrupt data, but it risks database is locked timeouts—especially with timeout = 5 in pytest config. The fix is to commit and close before yielding:
PasswordHelper is imported three times inside separate fixture bodies. It should be a single top-level import alongside the existing ones on line 1–4. Deferred imports here provide no benefit and obscure dependencies.
3. test_db fixture scope is implicit — tests/conftest.py:97
test_engine is explicitly scope="session", but test_db (which depends on it and calls drop_all/create_all) has no explicit scope, defaulting to function. The asymmetry is not wrong, but it's easy to miss. Adding scope="function" explicitly would make the intent clear.
4. rbac_data not consumed by test_audit_rbac.py tests that previously passed with fewer permissions
The old test_audit_rbac.pyrbac_data only gave role_id=1 permissions id=1 and id=2. The new shared rbac_data gives role 1 four permissions (including admin:*). The existing audit tests only assert on specific audit log entries and don't enumerate all permissions, so they still pass—but this is worth noting in case future audit tests assert on the exact permission set in extra.
Positive Notes
Moving to file-based SQLite + session-scoped engine with tmp_path_factory is the right approach to avoid the "early drop" problem described in the PR.
Using @event.listens_for(engine.sync_engine, "connect") for the PRAGMA is the correct pattern for async engines.
Adding engine.dispose() in test_mixins.py is a good cleanup improvement.
try/finally around yields in test_db and mixin_db correctly guards against teardown being skipped on test failure.
asyncio_default_fixture_loop_scope = "session" and asyncio_default_test_loop_scope = "session" in pyproject.toml is the correct fix for the loop scope deprecation warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #129
Summary of Changes
Breaking Changes
N/A
Checklist