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[polyfactory.factories.base.BaseFactory[Any]]) Any[source]

Call self as a function.

polyfactory.pytest_plugin.register_fixture(factory: type[polyfactory.factories.base.BaseFactory[Any]] | None = None, *, scope: Literal['session', 'package', 'module', 'class', 'function'] | Callable[[str, Config], Literal['session', 'package', 'module', 'class', 'function']] = 'function', autouse: bool = False, name: str | None = None) Any[source]

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.