pytest_plugin

class polyfactory.pytest_plugin.FactoryFixture[source]

Bases: object

Decorator that creates a pytest fixture from a factory

__init__(scope: Literal['session', 'package', 'module', 'class', 'function'] | Callable[[str, Config], Literal['session', 'package', 'module', 'class', 'function']] = 'function', autouse: bool = False, name: str | None = None) None[source]

Create a factory fixture decorator

Parameters:
  • scope – Fixture scope

  • autouse – Autouse the fixture

  • name – Fixture name

__call__(factory: type[T]) Callable[[], type[T]][source]

Call self as a function.

polyfactory.pytest_plugin.register_fixture(factory: None = None, *, scope: Scope = 'function', autouse: bool = False, name: str | None = None) FactoryFixture[source]
polyfactory.pytest_plugin.register_fixture(factory: type[T], *, scope: Scope = 'function', autouse: bool = False, name: str | None = None) Callable[[], type[T]]

A decorator that allows registering model factories as fixtures.

Parameters:
  • factory – An optional factory class to decorate.

  • scope – Pytest scope.

  • autouse – Auto use fixture.

  • name – Fixture name.

Returns:

A fixture factory instance.