@@ -126,7 +126,7 @@ def create_test_app():
126126
127127
128128# ===== App without lifespan for tests =====
129- @pytest_asyncio .fixture (scope = "session" , loop_scope = "session" )
129+ @pytest_asyncio .fixture (scope = "session" )
130130async def app ():
131131 """Create FastAPI app once per session/worker to avoid Pydantic schema crashes."""
132132 application = create_test_app ()
@@ -138,15 +138,15 @@ async def app():
138138 await container .close ()
139139
140140
141- @pytest_asyncio .fixture (scope = "session" , loop_scope = "session" )
141+ @pytest_asyncio .fixture (scope = "session" )
142142async def app_container (app ): # type: ignore[valid-type]
143143 """Expose the Dishka container attached to the app."""
144144 container : AsyncContainer = app .state .dishka_container # type: ignore[attr-defined]
145145 return container
146146
147147
148148# ===== Client (function-scoped for clean cookies per test) =====
149- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
149+ @pytest_asyncio .fixture
150150async def client (app ) -> AsyncGenerator [httpx .AsyncClient , None ]: # type: ignore[valid-type]
151151 # Use httpx with ASGI app directly
152152 # The app fixture already handles lifespan via LifespanManager
@@ -168,19 +168,19 @@ async def _container_scope(container: AsyncContainer):
168168 yield scope
169169
170170
171- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
171+ @pytest_asyncio .fixture
172172async def scope (app_container : AsyncContainer ): # type: ignore[valid-type]
173173 async with _container_scope (app_container ) as s :
174174 yield s
175175
176176
177- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
177+ @pytest_asyncio .fixture
178178async def db (scope ) -> AsyncGenerator [Database , None ]: # type: ignore[valid-type]
179179 database : Database = await scope .get (Database )
180180 yield database
181181
182182
183- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
183+ @pytest_asyncio .fixture
184184async def redis_client (scope ) -> AsyncGenerator [redis .Redis , None ]: # type: ignore[valid-type]
185185 client : redis .Redis = await scope .get (redis .Redis )
186186 yield client
@@ -222,7 +222,7 @@ def shared_admin_credentials():
222222 }
223223
224224
225- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
225+ @pytest_asyncio .fixture
226226async def shared_user (client : httpx .AsyncClient , shared_user_credentials ):
227227 creds = shared_user_credentials
228228 # Always attempt to register; DB is wiped after each test
@@ -233,7 +233,7 @@ async def shared_user(client: httpx.AsyncClient, shared_user_credentials):
233233 return {** creds , "csrf_token" : csrf , "headers" : {"X-CSRF-Token" : csrf }}
234234
235235
236- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
236+ @pytest_asyncio .fixture
237237async def shared_admin (client : httpx .AsyncClient , shared_admin_credentials ):
238238 creds = shared_admin_credentials
239239 r = await client .post ("/api/v1/auth/register" , json = creds )
@@ -243,7 +243,7 @@ async def shared_admin(client: httpx.AsyncClient, shared_admin_credentials):
243243 return {** creds , "csrf_token" : csrf , "headers" : {"X-CSRF-Token" : csrf }}
244244
245245
246- @pytest_asyncio .fixture ( scope = "function" , loop_scope = "session" )
246+ @pytest_asyncio .fixture
247247async def another_user (client : httpx .AsyncClient ):
248248 username = f"test_user_{ uuid .uuid4 ().hex [:8 ]} "
249249 email = f"{ username } @example.com"
0 commit comments