fastware v0.1.0 /src.fastware.testing
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

python
def _start_loop(self) -> None

Run the event loop in a background thread.

#_run

python
def _run(self, coro: Any) -> Any

Schedule a coroutine on the background loop and wait for result.

#get

python
def get(self, *args: Any, **kwargs: Any) -> Any

#post

python
def post(self, *args: Any, **kwargs: Any) -> Any

#put

python
def put(self, *args: Any, **kwargs: Any) -> Any

#patch

python
def patch(self, *args: Any, **kwargs: Any) -> Any

#delete

python
def delete(self, *args: Any, **kwargs: Any) -> Any

#options

python
def options(self, *args: Any, **kwargs: Any) -> Any
python
def head(self, *args: Any, **kwargs: Any) -> Any

#close

python
def close(self) -> None