@@ -146,7 +146,7 @@ async def app_container(app): # type: ignore[valid-type]
146146
147147
148148# ===== Client (function-scoped for clean cookies per test) =====
149- @pytest_asyncio .fixture (scope = "function" )
149+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
171+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
177+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
183+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
225+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
236+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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" )
246+ @pytest_asyncio .fixture (scope = "function" , loop_scope = "session" )
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