Skip to content

xtr_dependency_injection.testing

Booting a kernel in tests, and the zero-config check every bundle's suite runs.

apply_overrides

apply_overrides(compiled: CompiledKernel, overrides: Mapping[type | tuple[type, Hashable], object]) -> None

Install overrides on compiled before it boots.

A key is a type, or a (type, qualifier) pair for a qualified service. Apply them before booting, so every boot hook already sees the replacements — :func:boot_for_test does exactly that.

boot_for_test async

boot_for_test(kernel: Kernel, /, *, env: str = 'test', overrides: Mapping[type | tuple[type, Hashable], object] = _NO_OVERRIDES) -> BootedKernel

Build kernel for env, apply overrides, and boot it.

Overrides are in place before any boot hook runs. A key is a type, or a (type, qualifier) pair for a qualified service::

async with await boot_for_test(kernel, overrides={Mailer: FakeMailer()}) as booted:
    ...

assert_zero_config async

assert_zero_config(bundle_cls: type[AnyBundle]) -> None

Build, boot and shut down a kernel of bundle_cls alone, with its default config.

Its requirements come from @required_bundle declarations; nothing is scanned. Call it from every bundle's test suite: a bundle that arrives transitively must work without the application configuring it.

Raises:

  • Exception –

    Whatever building, booting or shutting down raised.