HTML 原文 · 完整 Markdown · 纯文本 · 分段目录 · ← 上一段 · 下一段 →

08-FastAPI 项目为什么要尽早上异步测试和 Ruff

第 16 / 26 段:搭好异步测试基础设施

FastAPI 工程化实践 · 发布 2026-03-28 · 更新 2026-11-11 · 标签:FastAPI、Testing、Ruff、DX

await conn.rollback() # 回滚外层事务

@pytest_asyncio.fixture async def client(db_session: AsyncSession): async def override_get_db(): yield db_session

app.dependency_overrides[get_db] = override_get_db

async with AsyncClient( transport=ASGITransport(app=app), base_url="http://test", ) as ac: yield ac

app.dependency_overrides.clear()