fields¶
- class polyfactory.fields.WrappedCallable[source]¶
Bases:
TypedDict
A ref storing a callable. This class is a utility meant to prevent binding of methods.
- class polyfactory.fields.Require[source]¶
Bases:
object
A factory field that marks an attribute as a required build-time kwarg.
- class polyfactory.fields.Ignore[source]¶
Bases:
object
A factory field that marks an attribute as ignored.
- class polyfactory.fields.Use[source]¶
Bases:
Generic
[P
,T
]Factory field used to wrap a callable.
The callable will be invoked whenever building the given factory attribute.
- class polyfactory.fields.PostGenerated[source]¶
Bases:
object
Factory field that allows generating values after other fields are generated by the factory.
- class polyfactory.fields.Fixture[source]¶
Bases:
object
Factory field to create a pytest fixture from a factory.
- class polyfactory.fields.Param[source]¶
Bases:
Generic
[T
]A constant parameter that can be used by other fields but will not be passed to the final object.
If a value for the parameter is not passed in the field’s definition, it must be passed at build time. Otherwise, a MissingParamException will be raised.
- __init__(param: ~polyfactory.fields.T | ~typing.Callable[[...], ~polyfactory.fields.T] | type[polyfactory.field_meta.Null] = <class 'polyfactory.field_meta.Null'>, is_callable: bool = False, **kwargs: ~typing.Any) None [source]¶
Designate a parameter.
- Parameters:
param¶ – A constant or an unpassed value that can be referenced later
- to_value(from_build: ~polyfactory.fields.T | ~typing.Callable[[...], ~polyfactory.fields.T] | type[polyfactory.field_meta.Null] = <class 'polyfactory.field_meta.Null'>, **kwargs: ~typing.Any) T [source]¶
Determines the value to use at build time
If a value was passed to the constructor, it will be used. Otherwise, the value passed at build time will be used. If no value was passed at build time, a MissingParamException will be raised.
- Parameters:
args¶ – from_build: The value passed at build time (if any).
- Returns:
The value
- Raises:
MissingParamException