API
define_factory
RETURNS | DESCRIPTION |
---|---|
FactoryDSL
|
The definition of factory |
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
aliases |
Alias attached to this factory. For example if you open you definition like this: it will match the previous definition. If alias is missing, it will target the main factory. You can also define multiple factories at once, using this syntaxe:
TYPE:
|
storage |
Let define how instances will be persisted when using
TYPE:
|
build
Build one model instance.
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
*specializations |
Where the first value is the factory alias, and the others are traits
TYPE:
|
overrides |
TYPE:
|
refine |
TYPE:
|
build_many
Build many model instances.
PARAMETER | DESCRIPTION |
---|---|
count |
TYPE:
|
model |
TYPE:
|
*specializations |
Where the first value is the factory alias, and the others are traits
TYPE:
|
overrides |
TYPE:
|
refine |
TYPE:
|
create
Create one model instance.
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
*specializations |
Where the first value is the factory alias, and the others are traits
TYPE:
|
overrides |
TYPE:
|
refine |
TYPE:
|
storage |
Tell how the instance is persisted. When not set, fallback to the one defined by
TYPE:
|
create_many
create_many(
count,
/,
model,
*specializations,
overrides=None,
refine=lambda: None,
storage=None,
)
Create many model instances.
PARAMETER | DESCRIPTION |
---|---|
count |
TYPE:
|
model |
TYPE:
|
*specializations |
Where the first value is the factory alias, and the others are traits
TYPE:
|
overrides |
TYPE:
|
refine |
TYPE:
|
storage |
Tell how instances are persisted. When not set, fallback to the one defined by
TYPE:
|
attributes_for
Get attributes for one model instance
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
*specializations |
Where the first value is the factory alias, and the others are traits
TYPE:
|
overrides |
TYPE:
|
Attributes
module-attribute
Computed
dataclass
Bases: ValueProvider[T]
dependencies
class-attribute
instance-attribute
Cycle
dataclass
Bases: ValueProvider[T]
dependencies
class-attribute
instance-attribute
Sequence
dataclass
Bases: ValueProvider[T]
dependencies
class-attribute
instance-attribute
wrapped
class-attribute
instance-attribute
Any callable where first argument is the index of the sequence counter,
and other arguments are members of Context
.
For example, a simple counter:
seq = Sequence(lambda i: f"rank#{i}")
assert seq() == "rank#0"
assert seq() == "rank#1"
assert seq() == "rank#2"
Generate email based on instance.name and counter index:
Name
module-attribute
Persist
Bases: Protocol[T_contrat]
__call__
PARAMETER | DESCRIPTION |
---|---|
instance |
TYPE:
|
context |
TYPE:
|
UserHook
module-attribute
Any callable that has 2 parameters: instance and context.
PARAMETER | DESCRIPTION |
---|---|
instance |
the instance being build
TYPE:
|
context |
the context
TYPE:
|
Example:
Context
module-attribute
Set of attributes currently being collected and transient data.
FactoryDSL
dataclass
set
associate
PARAMETER | DESCRIPTION |
---|---|
attr |
TYPE:
|
model |
TYPE:
|
*traits |
TYPE:
|
overrides |
TYPE:
|
strategy |
TYPE:
|
trait
RETURNS | DESCRIPTION |
---|---|
TraitDSL
|
The definition of factory |
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
add_hook
Register a hook Example:
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
callback |
TYPE:
|
hook
Decorator used to register hook
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable[[UserHook], None]
|
decorator |
Example:
derived_factory
Define a sub factory that inherits from current.
PARAMETER | DESCRIPTION |
---|---|
aliases |
TYPE:
|
storage |
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FactoryDSL
|
The definition of factory |
TransientDSL
dataclass
TraitDSL
dataclass
set
associate
PARAMETER | DESCRIPTION |
---|---|
attr |
TYPE:
|
model |
TYPE:
|
*traits |
TYPE:
|
overrides |
TYPE:
|
strategy |
TYPE:
|