88from asgi_lifespan import LifespanManager
99from fastapi import FastAPI
1010from sqlalchemy .pool import NullPool
11- from alembic .config import Config
12- from alembic import command
1311
1412from config import test_connection , settings , BaseModel
1513from config import db_connection
2220)
2321
2422
25- cfg = Config ()
26- cfg .set_main_option (
27- 'sqlalchemy.url' ,
28- settings .test_db .url ,
29- )
30- cfg .set_main_option ('script_location' ,
31- settings .alembic .MIGRATION_PATH .as_posix (),
32- )
33-
34-
3523@pytest .fixture (scope = 'session' , autouse = True )
3624def event_loop (request ):
3725 loop = asyncio .get_event_loop_policy ().new_event_loop ()
@@ -50,7 +38,6 @@ async def app() -> AsyncGenerator[LifespanManager, Any]:
5038 async def lifespan (app : FastAPI ):
5139 async with db_setup .engine .begin () as conn :
5240 await conn .run_sync (BaseModel .metadata .create_all )
53- await conn .run_sync (alembic_do_upgrade )
5441 yield
5542 await conn .run_sync (BaseModel .metadata .drop_all )
5643
@@ -76,9 +63,7 @@ async def client(app: FastAPI) -> AsyncGenerator[httpx.AsyncClient, Any]:
7663 yield client
7764
7865
79- def alembic_do_upgrade (connection ):
80- """
81- Upgrade миграция алембик
82- """
83- cfg .attributes ['connection' ] = connection
84- command .upgrade (cfg , 'head' )
66+ @pytest_asyncio .fixture ()
67+ async def get_async_session ():
68+ async with db_setup .session () as session :
69+ yield session
0 commit comments