From 5aa13c7d33f818a83cf79268410f621ce99f1b4d Mon Sep 17 00:00:00 2001 From: Eneko Ruiz <196690101+eneekoruiz@users.noreply.github.com> Date: Tue, 13 Oct 2026 11:46:25 +0200 Subject: [PATCH] docs: distinguish Flask and FastAPI testing fixtures (cherry picked from commit 2353740d9eef728c1560a22602ba4801cea1d77a) --- pi/core/skills/python-testing/SKILL.md | 16 ++++++++++------ skills/python-testing/SKILL.md | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pi/core/skills/python-testing/SKILL.md b/pi/core/skills/python-testing/SKILL.md index ddfcc0abc..b9e7d7437 100644 --- a/pi/core/skills/python-testing/SKILL.md +++ b/pi/core/skills/python-testing/SKILL.md @@ -224,7 +224,7 @@ def test_without_fixture_call(): assert Config.get_setting("debug") is False ``` -### Conftest.py for Shared Fixtures +### Conftest.py for Shared Fixtures (Flask) ```python # tests/conftest.py @@ -484,14 +484,18 @@ async def test_async_with_fixture(async_client): assert response.status_code == 200 ``` -### Async Fixture +### Async Fixture (FastAPI) ```python -@pytest.fixture +import pytest +import pytest_asyncio +from httpx import ASGITransport, AsyncClient + +@pytest_asyncio.fixture async def async_client(): """Async fixture providing async test client.""" - app = create_app() - async with app.test_client() as client: + app = create_app() # Returns a FastAPI application + async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: yield client @pytest.mark.asyncio @@ -661,7 +665,7 @@ class TestUserService: ## Common Patterns -### Testing API Endpoints (FastAPI/Flask) +### Testing API Endpoints (Flask) ```python @pytest.fixture diff --git a/skills/python-testing/SKILL.md b/skills/python-testing/SKILL.md index ddfcc0abc..b9e7d7437 100644 --- a/skills/python-testing/SKILL.md +++ b/skills/python-testing/SKILL.md @@ -224,7 +224,7 @@ def test_without_fixture_call(): assert Config.get_setting("debug") is False ``` -### Conftest.py for Shared Fixtures +### Conftest.py for Shared Fixtures (Flask) ```python # tests/conftest.py @@ -484,14 +484,18 @@ async def test_async_with_fixture(async_client): assert response.status_code == 200 ``` -### Async Fixture +### Async Fixture (FastAPI) ```python -@pytest.fixture +import pytest +import pytest_asyncio +from httpx import ASGITransport, AsyncClient + +@pytest_asyncio.fixture async def async_client(): """Async fixture providing async test client.""" - app = create_app() - async with app.test_client() as client: + app = create_app() # Returns a FastAPI application + async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: yield client @pytest.mark.asyncio @@ -661,7 +665,7 @@ class TestUserService: ## Common Patterns -### Testing API Endpoints (FastAPI/Flask) +### Testing API Endpoints (Flask) ```python @pytest.fixture