Skip to content



We use pytest, httpx, pytest-asyncio, and asgi-lifespan to set up a test application.

Please walk through the example from asgi-lifespan, as it does a fantastic job setting up how a Starlette application is used!

FastRF/FastAPI application directly inherit from Starlette!

Client Setup

Our goal is to have a pytest fixture that is a client that can send requests to our application. This will also mimic the application that comes with fastrf

The main differences from the example from asgi-lifespan are highlighted below.

import httpx
import pytest
from asgi_lifespan import LifespanManager
from import app
from import router as noise_figure_router

async def test_app():
    async def startup():
        print("Starting up")

    async def shutdown():
        print("Shutting down")

    ROUTERS = (noise_figure_router,)

    for r in ROUTERS:

    async with LifespanManager(app):
        print("We're in!")
        yield app

async def client(test_app):
    async with httpx.AsyncClient(
        app=test_app, base_url="http://localhost:8888"
    ) as client:
        print("Client is ready")
        yield client

We now have an asynchronous HTTP client as a pytest fixture! 🎉 🙌