File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """Integration tests for sync engine used inside an async context."""
2+
3+ import asyncio
4+
5+ import pytest
6+ from sqlalchemy import create_engine , text
7+
8+
9+ @pytest .mark .integration
10+ class TestSyncEngineInAsyncContext :
11+ def test_sync_engine_inside_running_loop (self , engine_url : str ) -> None :
12+ """Sync engine must work when called from inside a running event loop.
13+
14+ This simulates the scenario where a sync SQLAlchemy engine is used
15+ during app startup inside an async server like uvicorn.
16+ """
17+
18+ async def _run_inside_loop () -> str :
19+ engine = create_engine (engine_url )
20+ with engine .connect () as conn :
21+ result = conn .execute (text ("SELECT 'ok'" ))
22+ row = result .fetchone ()
23+ engine .dispose ()
24+ assert row is not None
25+ return str (row [0 ])
26+
27+ result = asyncio .run (_run_inside_loop ())
28+ assert result == "ok"
Original file line number Diff line number Diff line change @@ -58,6 +58,25 @@ def test_import_dbapi(self) -> None:
5858 dbapi = DqliteDialect_aio .import_dbapi ()
5959 assert hasattr (dbapi , "aconnect" )
6060
61+ def test_import_dbapi_has_paramstyle (self ) -> None :
62+ """Async dbapi module must expose paramstyle for SQLAlchemy dialect init."""
63+ dbapi = DqliteDialect_aio .import_dbapi ()
64+ assert dbapi .paramstyle == "qmark"
65+
66+ def test_import_dbapi_has_module_attributes (self ) -> None :
67+ """Async dbapi module must expose PEP 249 attributes for SQLAlchemy."""
68+ dbapi = DqliteDialect_aio .import_dbapi ()
69+ assert dbapi .apilevel == "2.0"
70+ assert dbapi .threadsafety == 1
71+
72+ def test_create_async_engine (self ) -> None :
73+ """create_async_engine must not raise during dialect initialization."""
74+ from sqlalchemy .ext .asyncio import create_async_engine
75+
76+ engine = create_async_engine ("dqlite+aio://localhost:19001/test" )
77+ assert engine .dialect .name == "dqlite"
78+ assert engine .dialect .driver == "dqlitedbapi_aio"
79+
6180
6281class TestURLParsing :
6382 def test_parse_basic_url (self ) -> None :
You can’t perform that action at this time.
0 commit comments