On this page
Sync and async test clients for fastware apps, wrapping httpx with ASGITransport to exercise routes without starting a real network server.
#src.fastware.testing
#src.fastware.testing
Sync and async test clients for fastware apps, wrapping httpx with ASGITransport to exercise routes without starting a real network server.
Provides sync and async test clients that wrap httpx with ASGITransport, so tests can exercise a fastware app without starting a real server. Both clients run the ASGI lifespan protocol on enter and shut down on exit.
httpx is a dev/test dependency -- this module should only be imported in test contexts.
#AsyncTestClient
Async test client for fastware apps.
Use as an async context manager::
async with AsyncTestClient(app) as client: resp = await client.get("/health")
#_SyncTestClient
Sync test client for fastware apps.
Runs an AsyncClient on a background event loop so that sync test code can call .get(), .post() etc. without await.
Usage::
with _SyncTestClient(app) as client: resp = client.get("/health") assert resp.status_code == 200
The class is named _SyncTestClient internally and exported as TestClient to avoid pytest treating it as a test class (pytest skips classes whose name starts with _).
#_start_loop
def _start_loop(self) -> NoneRun the event loop in a background thread.
#_run
def _run(self, coro: Any) -> AnySchedule a coroutine on the background loop and wait for result.
#get
def get(self, *args: Any, **kwargs: Any) -> Any#post
def post(self, *args: Any, **kwargs: Any) -> Any#put
def put(self, *args: Any, **kwargs: Any) -> Any#patch
def patch(self, *args: Any, **kwargs: Any) -> Any#delete
def delete(self, *args: Any, **kwargs: Any) -> Any#options
def options(self, *args: Any, **kwargs: Any) -> Any#head
def head(self, *args: Any, **kwargs: Any) -> Any#close
def close(self) -> None