From 26b0523875173ff1bb3caf8b8eb719fa79ca8d15 Mon Sep 17 00:00:00 2001 From: Eneko Ruiz <196690101+eneekoruiz@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:14:12 +0200 Subject: [PATCH] docs: explain FastAPI async fixture lifespan management --- pi/core/skills/python-testing/SKILL.md | 3 +++ skills/python-testing/SKILL.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pi/core/skills/python-testing/SKILL.md b/pi/core/skills/python-testing/SKILL.md index b9e7d7437..713aeb429 100644 --- a/pi/core/skills/python-testing/SKILL.md +++ b/pi/core/skills/python-testing/SKILL.md @@ -486,6 +486,9 @@ async def test_async_with_fixture(async_client): ### Async Fixture (FastAPI) +`ASGITransport` does not run lifespan events. If the app needs startup/shutdown, wrap the client block in `async with LifespanManager(app) as manager:` (from `asgi_lifespan`) +and use `ASGITransport(app=manager.app)`. See [FastAPI's async testing guidance](https://github.com/fastapi/fastapi/blob/master/docs/en/docs/advanced/async-tests.md). + ```python import pytest import pytest_asyncio diff --git a/skills/python-testing/SKILL.md b/skills/python-testing/SKILL.md index b9e7d7437..713aeb429 100644 --- a/skills/python-testing/SKILL.md +++ b/skills/python-testing/SKILL.md @@ -486,6 +486,9 @@ async def test_async_with_fixture(async_client): ### Async Fixture (FastAPI) +`ASGITransport` does not run lifespan events. If the app needs startup/shutdown, wrap the client block in `async with LifespanManager(app) as manager:` (from `asgi_lifespan`) +and use `ASGITransport(app=manager.app)`. See [FastAPI's async testing guidance](https://github.com/fastapi/fastapi/blob/master/docs/en/docs/advanced/async-tests.md). + ```python import pytest import pytest_asyncio