Skip to content

Commit 29e2240

Browse files
committed
Use asgi-lifespan to ensure the lifespan events are used in test
1 parent 0f8cc87 commit 29e2240

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev = [
3434
"pytest-mock",
3535
"pytest-asyncio",
3636
"httpx",
37+
"asgi-lifespan",
3738
"hypothesis",
3839
"deepdiff",
3940
"pytest-xdist",

tests/conftest.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010
from _pytest.config import Config
1111
from _pytest.nodes import Item
12+
from asgi_lifespan import LifespanManager
1213
from sqlalchemy import text
1314
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
1415

@@ -85,11 +86,14 @@ async def override_userdb() -> AsyncIterator[AsyncConnection]:
8586

8687
app.dependency_overrides[expdb_connection] = override_expdb
8788
app.dependency_overrides[userdb_connection] = override_userdb
88-
async with httpx.AsyncClient(
89-
transport=httpx.ASGITransport(app=app),
90-
base_url="http://test",
91-
follow_redirects=True,
92-
) as client:
89+
async with (
90+
LifespanManager(app) as manager,
91+
httpx.AsyncClient(
92+
transport=httpx.ASGITransport(app=manager.app),
93+
base_url="http://test",
94+
follow_redirects=True,
95+
) as client,
96+
):
9397
yield client
9498

9599

0 commit comments

Comments
 (0)