ward.fixtures
¶
Standard API¶
- ward.fixtures.fixture(func=None, *, scope: Optional[Union[ward.models.Scope, str]] = <Scope.Test: 'test'>)¶
Decorator which will cause the wrapped function to be collected and treated as a fixture.
- Parameters
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.
- fn
The Python function object corresponding to this fixture.
- Type
Callable
- gen
The generator, if applicable to this fixture.
- Type
Union[Generator, AsyncGenerator]
- resolved_val
The value returned by calling the fixture function (fn).
- Type
Any
- deps()
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 contains 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.
- parents() → List[ward.fixtures.Fixture]
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()
Tears down the fixture by calling next or __anext__().