Standard API

ward.fixtures.fixture(func=None, *, scope: Union[ward.models.Scope, str] = <Scope.Test: 'test'>)

Decorator which will cause the wrapped function to be collected and treated as a fixture.

  • func – The wrapped function which should yield or return some data required to execute a test.

  • scope – The scope of a fixture determines how long it can be cached for (and therefore how frequently the fixture should be regenerated).

ward.fixtures.using(*using_args, **using_kwargs)

An alternative to the default param method of injecting fixtures into tests. Allows you to avoid using keyword arguments in your test definitions.

Plugin API

This section contains items from this module that are intended for use by plugin authors or those contributing to Ward itself. If you’re just using Ward to write your tests, this section isn’t relevant.

class ward.fixtures.Fixture(fn: Callable, gen: Optional[Union[Generator, AsyncGenerator]] = None, resolved_val: Optional[Any] = None)

Represents a piece of data that will be used in a test.


The Python function object corresponding to this fixture.




The generator, if applicable to this fixture.


Optional[Union[Generator, AsyncGenerator]]


The value returned by calling the fixture function (fn).




The dependencies of the fixture.

property is_async_generator_fixture

True if this fixture is an async generator.

property is_coroutine_fixture

True if the fixture is defined with ‘async def’.

property is_generator_fixture

True if the fixture is a generator function (and thus may contain teardown code).

property key: str

A unique key used to identify fixture in the fixture cache. A string of the form ‘{path}::{name}’

property line_number: int

The line number that the fixture is defined on.

property module_name

The name of the module the fixture is defined in.

property name

The name of the fixture function.


Return the parent fixtures of this fixture, as a list of Fixtures.

property path

The pathlib.Path of the module the fixture is defined in.

teardown(capture_output: bool)ward.fixtures.TeardownResult

Tears down the fixture by calling next or __anext__().