Unit tests: resolve a provider
Create a testing module from the modules or providers you care about, compile it, and resolve what you need. Providers are singletons, just like in the running app.
import pytest
from austial.testing import Test
from .cats_module import CatsModule
from .cats_service import CatsService
@pytest.mark.asyncio
async def test_creates_and_lists_cats():
module = await Test.create_testing_module(imports=[CatsModule]).compile()
service = module.get(CatsService)
service.create(CreateCatDto(name="Whiskers"))
assert len(service.find_all()) == 1E2E tests: real HTTP routes, in process
Build an application from the testing module and drive it with an httpx client over an ASGI transport. The full request lifecycle runs, including guards, pipes, interceptors and exception filters.
from httpx import ASGITransport, AsyncClient
module = await Test.create_testing_module(
controllers=[CatsController], providers=[CatsService]
).compile()
app = module.create_austial_application()
await app.init()
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
response = await client.post("/cats", json={"name": "Whiskers"})Tests ship with the scaffold
austial new creates unit and e2e test folders and pre-commit hooks that run ruff, mypy and pytest, so the verification loop is in place from the first commit.
Frequently asked questions
Do I need to start a server to test routes?
No. The e2e pattern uses httpx with an ASGI transport, so requests run in process against the real application.
Can I test one module in isolation?
Yes. create_testing_module takes imports, controllers and providers, and builds an anonymous root module from whatever you pass.
Which test runner does it use?
The scaffold uses pytest, with ruff and mypy in pre-commit hooks.