Skip to content

repeated-test-composition

Sibling tests repeat service collaborator wiring or managed ASGI HTTP clients.

Why

Repeated assembly hides scenario differences and spreads dependency signature changes across tests.

Fix

Move shared assembly into a function-scoped fixture or typed factory fixture; keep scenario values explicit.

Examples

Before — flagged Share managed test-client assembly
tests/test_client.py
from httpx import AsyncClient, ASGITransport
async def test_case_0(app):
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as client:
assert await client.get("/")
async def test_case_1(app):
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as client:
assert await client.get("/")
async def test_case_2(app):
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as client:
assert await client.get("/")
After — preferred Request a managed test client fixture
tests/test_client.py
async def test_response(client):
assert await client.get("/")