Skip to content

Commit be0f4e2

Browse files
author
Ferran Pons Serra
committed
refactor(tests): use async context manager in eager initialization test
Address review feedback: use `async with` instead of try/finally for DatabaseSessionService resource management, consistent with other tests.
1 parent e27aad7 commit be0f4e2

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

tests/unittests/sessions/test_session_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,7 @@ async def test_public_prepare_tables_eager_initialization():
11861186
"""Calling the public prepare_tables() eagerly initializes tables so that
11871187
the first real database operation does not pay the setup cost.
11881188
"""
1189-
service = DatabaseSessionService('sqlite+aiosqlite:///:memory:')
1190-
try:
1189+
async with DatabaseSessionService('sqlite+aiosqlite:///:memory:') as service:
11911190
# Before calling prepare_tables, tables are not created.
11921191
assert not service._tables_created
11931192
assert service._db_schema_version is None
@@ -1204,8 +1203,6 @@ async def test_public_prepare_tables_eager_initialization():
12041203
app_name='app', user_id='user', session_id='s1'
12051204
)
12061205
assert session.id == 's1'
1207-
finally:
1208-
await service.close()
12091206

12101207

12111208
@pytest.mark.asyncio

0 commit comments

Comments
 (0)