Options¶
Factory-level Options¶
Options can be supplied to register_at
at the factory level to alter
the default behavior when calling a factory.
Factory-level options include:
commit:
True
/False
(defaultTrue
)Whether the given factory should commit the models it produces.
merge:
True
/False
(defaultFalse
)Whether the given factory should
Session.add
the models it produces, orSession.merge
them.This option can be useful for obtaining a reference to some model you know is already in the database, but you dont currently have a handle on.
For example:
@register_at("widget", name="default", merge=True)
def default_widget():
return Widget()
Call-level Options¶
All options available at the factory-level can also be provided at the call-site
when calling the factories, although their arguments are postfixed with a
trailing _
to avoid colliding with normal factory arguments.
def test_widget(mf):
widget = mf.widget.default(merge_=True, commit_=True)