Bugfix:
- Fix passing deep context to a
~factory.SubFactory
(Foo(x__y__z=factory.Faker('name')
)
Bugfix:
- Fix
~factory.fuzzy.FuzzyFloat
to return a 15 decimal digits precision float by default451
: Restore~factory.django.FileField
to a~factory.declarations.ParameteredAttribute
, relying on composition to parse the provided parameters.389
: Fix random state management withfaker
.466
: Restore mixing~factory.Trait
and~factory.post_generation
.
Bugfix:
443
: Don't crash when callingfactory.Iterator.reset()
on a brand new iterator.
New:
397
: Allow afactory.Maybe
to contain a~factory.PostGenerationDeclaration
. This also applies tofactory.Trait
, since they use afactory.Maybe
declaration internally.
Bugfix:
- Fix declaration corruption bug when a factory defined foo__bar__baz=1 and a caller provided a foo__bar=x parameter at call time: this got merged into the factory's base declarations.
Bugfix:
- Fix packaging issues (see zestsoftware/zest.releaser#212)
- Don't crash when debugging PostGenerationDeclaration
This version brings massive changes to the core engine, thus reducing the number of corner cases and weird behaviourrs.
New:
275
: factory.fuzzy and factory.faker now use the same random seed.- Add
factory.Maybe
, which chooses among two possible declarations based on another field's value (powers the~factory.Trait
feature).~factory.PostGenerationMethodCall
only allows to pass one positional argument; use keyword arguments for extra parameters.
Deprecation:
- factory.fuzzy.get_random_state is deprecated, factory.random.get_random_state should be used instead.
- factory.fuzzy.set_random_state is deprecated, factory.random.set_random_state should be used instead.
- factory.fuzzy.reseed_random is deprecated, factory.random.reseed_random should be used instead.
Bugfix:
- Fix packaging issues.
New:
240
: Call post-generation declarations in the order they were declared, thanks to Oleg Pidsadnyi.309
: Provide new options for SQLAlchemy session persistence
Bugfix:
334
: Adjust for the package change infaker
New:
267
: Addfactory.LazyFunction
to remove unneeded lambda parameters, thanks to Hervé Cauwelier.251
: Addparameterized factories <parameters>
andtraits <factory.Trait>
256
,292
: Improve error messages in corner cases
Removed:
278
: Formally drop support for Python2.6
Warning
Version 2.7.0 moves all error classes to factory.errors. This breaks existing import statements for any error classes except those importing FactoryError directly from the factory module.
New:
262
: Allow optional forced flush on SQLAlchemy, courtesy of Minjung.
New:
- Add
factory.FactoryOptions.rename
to help handle conflicting names (206
)- Add support for random-yet-realistic values through fake-factory, through the
factory.Faker
class.factory.Iterator
no longer begins iteration of its argument at import time, thus allowing to pass in a lazy iterator such as a Django queryset (i.efactory.Iterator(models.MyThingy.objects.all())
).- Simplify imports for ORM layers, now available through a simple
factory
import, atfactory.alchemy.SQLAlchemyModelFactory
/factory.django.DjangoModelFactory
/factory.mongoengine.MongoEngineFactory
.
Bugfix:
201
: Properly handle custom Django managers when dealing with abstract Django models.212
: Fixfactory.django.mute_signals
to handle Django's signal caching228
: Don't loaddjango.apps.apps.get_model()
until required219
: Stop usingmogo.model.Model.new()
, deprecated 4 years ago.
Bugfix:
- Add support for Django 1.7/1.8
- Add support for mongoengine>=0.9.0 / pymongo>=2.1
Bugfix:
- Respect custom managers in
~factory.django.DjangoModelFactory
(see192
)- Allow passing declarations (e.g
~factory.Sequence
) as parameters to~factory.django.FileField
and~factory.django.ImageField
.
New:
- Add support for getting/setting
factory.fuzzy
's random state (see175
,185
).- Support lazy evaluation of iterables in
factory.fuzzy.FuzzyChoice
(see184
).- Support non-default databases at the factory level (see
171
)- Make
factory.django.FileField
andfactory.django.ImageField
non-post_generation, i.e normal fields also available insave()
(see141
).
Bugfix:
- Avoid issues when using
factory.django.mute_signals
on a base factory class (see183
).- Fix limitations of
factory.StubFactory
, that can now usefactory.SubFactory
and co (see131
).
Deprecation:
- Remove deprecated features from
v2.4.0
- Remove the auto-magical sequence setup (based on the latest primary key value in the database) for Django and SQLAlchemy; this relates to issues
170
,153
,111
,103
,92
,78
. See https://github.com/FactoryBoy/factory_boy/commit/13d310f for technical details.
Warning
Version 2.5.0 removes the 'auto-magical sequence setup' bug-and-feature. This could trigger some bugs when tests expected a non-zero sequence reference.
Warning
Version 2.5.0 removes features that were marked as deprecated in v2.4.0 <v2.4.0>
.
All FACTORY_*
-style attributes are now declared in a class Meta:
section:
# Old-style, deprecated
class MyFactory(factory.Factory):
FACTORY_FOR = models.MyModel
FACTORY_HIDDEN_ARGS = ['a', 'b', 'c']
# New-style
class MyFactory(factory.Factory):
class Meta:
model = models.MyModel
exclude = ['a', 'b', 'c']
A simple shell command to upgrade the code would be:
# sed -i: inplace update
# grep -l: only file names, not matching lines
sed -i 's/FACTORY_FOR =/class Meta:\n model =/' $(grep -l FACTORY_FOR $(find . -name '*.py'))
This takes care of all FACTORY_FOR
occurrences; the files containing other attributes to rename can be found with grep -R FACTORY .
Bugfix:
- Fix overriding deeply inherited attributes (set in one factory, overridden in a subclass, used in a sub-sub-class).
New:
- Add support for
factory.fuzzy.FuzzyInteger.step
, thanks to ilya-pirogov (120
)- Add
~factory.django.mute_signals
decorator to temporarily disable some signals, thanks to ilya-pirogov (122
)- Add
~factory.fuzzy.FuzzyFloat
(124
)- Declare target model and other non-declaration fields in a
class Meta
section.
Deprecation:
Use of
FACTORY_FOR
and otherFACTORY
class-level attributes is deprecated and will be removed in 2.5. Those attributes should now declared within theclass Meta <factory.FactoryOptions>
attribute:For
factory.Factory
:
- Rename
~factory.Factory.FACTORY_FOR
to~factory.FactoryOptions.model
- Rename
~factory.Factory.ABSTRACT_FACTORY
to~factory.FactoryOptions.abstract
- Rename
~factory.Factory.FACTORY_STRATEGY
to~factory.FactoryOptions.strategy
- Rename
~factory.Factory.FACTORY_ARG_PARAMETERS
to~factory.FactoryOptions.inline_args
- Rename
~factory.Factory.FACTORY_HIDDEN_ARGS
to~factory.FactoryOptions.exclude
For
factory.django.DjangoModelFactory
:
- Rename
~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE
to~factory.django.DjangoOptions.django_get_or_create
For
factory.alchemy.SQLAlchemyModelFactory
:
- Rename
~factory.alchemy.SQLAlchemyModelFactory.FACTORY_SESSION
to~factory.alchemy.SQLAlchemyOptions.sqlalchemy_session
Bugfix:
New:
Bugfix:
- Fixed sequence counter for
~factory.django.DjangoModelFactory
when a factory inherits from another factory relating to an abstract model.
Bugfix:
- Removed duplicated
~factory.alchemy.SQLAlchemyModelFactory
lurking infactory
(83
)- Properly handle sequences within object inheritance chains. If FactoryA inherits from FactoryB, and their associated classes share the same link, sequence counters will be shared (
93
)- Properly handle nested
~factory.SubFactory
overrides
New:
- The
~factory.django.DjangoModelFactory
now supports theFACTORY_FOR = 'myapp.MyModel'
syntax, making it easier to shove all factories in a single module (66
).- Add
factory.debug()
helper for easier backtrace analysis- Adding factory support for mongoengine with
~factory.mongoengine.MongoEngineFactory
.
New:
- The
~factory.Factory.ABSTRACT_FACTORY
keyword is now optional, and automatically set toTrue
if neither the~factory.Factory
subclass nor its parent declare the~factory.Factory.FACTORY_FOR
attribute (74
)
Bugfix:
- Properly retrieve the
color
keyword argument passed to~factory.django.ImageField
New:
- Add
~factory.fuzzy.FuzzyDate
thanks to saulshanabrook- Add
~factory.fuzzy.FuzzyDateTime
and~factory.fuzzy.FuzzyNaiveDateTime
.- Add a
~factory.builder.Resolver.factory_parent
attribute to the~factory.builder.Resolver
passed to~factory.LazyAttribute
, in order to access fields defined in wrapping factories.- Move
~factory.django.DjangoModelFactory
and~factory.mogo.MogoFactory
to their own modules (factory.django
andfactory.mogo
)- Add the
~factory.Factory.reset_sequence
classmethod to~factory.Factory
to ease resetting the sequence counter for a given factory.- Add debug messages to
factory
logger.- Add a
~factory.Iterator.reset
method to~factory.Iterator
(63
)- Add support for the SQLAlchemy ORM through
~factory.alchemy.SQLAlchemyModelFactory
(64
, thanks to Romain Commandé)- Add
factory.django.FileField
andfactory.django.ImageField
hooks for related Django model fields (52
)
Bugfix
- Properly handle non-integer pks in
~factory.django.DjangoModelFactory
(57
).- Disable
~factory.RelatedFactory
generation when a specific value was passed (62
, thanks to Gabe Koscky)
Deprecation:
- Rename
~factory.RelatedFactory
'sname
argument tofactory_related_name
(See58
)
New:
- When
~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE
is empty, useModel.objects.create()
instead ofModel.objects.get_or_create
.
New:
- Don't push
defaults
toget_or_create
when~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE
is not set.
New:
- Allow overriding the base factory class for
~factory.make_factory
and friends.- Add support for Python3 (Thanks to kmike and nkryptic)
- The default
~factory.Sequence.type
for~factory.Sequence
is nowint
- Fields listed in
~factory.Factory.FACTORY_HIDDEN_ARGS
won't be passed to the associated class' constructor- Add support for
get_or_create
in~factory.django.DjangoModelFactory
, through~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE
.- Add support for
~factory.fuzzy
attribute definitions.- The
Sequence
counter can be overridden when calling a generating function- Add
~factory.Dict
and~factory.List
declarations (Closes18
).
Removed:
- Remove associated class discovery
- Remove
~factory.InfiniteIterator
and~factory.infinite_iterator
- Remove
~factory.CircularSubFactory
- Remove
extract_prefix
kwarg to post-generation hooks.- Stop defaulting to Django's
Foo.objects.create()
when "creating" instances- Remove STRATEGY*
- Remove
~factory.Factory.set_building_function
/~factory.Factory.set_creation_function
Warning
This version deprecates many magic or unexplicit features that will be removed in v2.0.0.
Please read the changelog-1-3-0-upgrading
section, then run your tests with python -W default
to see all remaining warnings.
- Global:
- Rewrite the whole documentation
- Provide a dedicated
~factory.mogo.MogoFactory
subclass of~factory.Factory
- The Factory class:
- Better creation/building customization hooks at
factory.Factory._build
andfactory.Factory.create
- Add support for passing non-kwarg parameters to a
~factory.Factory
wrapped class through~factory.Factory.FACTORY_ARG_PARAMETERS
. - Keep the
~factory.Factory.FACTORY_FOR
attribute in~factory.Factory
classes
- Better creation/building customization hooks at
- Declarations:
- Allow
~factory.SubFactory
to solve circular dependencies between factories - Enhance
~factory.SelfAttribute
to handle "container" attribute fetching - Add a
~factory.Iterator.getter
to~factory.Iterator
declarations - A
~factory.Iterator
may be prevented from cycling by setting its~factory.Iterator.cycle
argument toFalse
- Allow overriding default arguments in a
~factory.PostGenerationMethodCall
when generating an instance of the factory - An object created by a
~factory.django.DjangoModelFactory
will be saved again after~factory.PostGeneration
hooks execution
- Allow
The following features have been deprecated and will be removed in an upcoming release.
- Declarations:
~factory.InfiniteIterator
is deprecated in favor of~factory.Iterator
~factory.CircularSubFactory
is deprecated in favor of~factory.SubFactory
- The
extract_prefix
argument to~factory.post_generation
is now deprecated
- Factory:
- Usage of
~factory.Factory.set_creation_function
and~factory.Factory.set_building_function
are now deprecated - Implicit associated class discovery is no longer supported, you must set the
~factory.Factory.FACTORY_FOR
attribute on all~factory.Factory
subclasses
- Usage of
This version deprecates a few magic or undocumented features. All warnings will turn into errors starting from v2.0.0.
In order to upgrade client code, apply the following rules:
- Add a
FACTORY_FOR
attribute pointing to the target class to each~factory.Factory
, instead of relying on automagic associated class discovery - When using factory_boy for Django models, have each factory inherit from
~factory.django.DjangoModelFactory
- Replace
factory.CircularSubFactory('some.module', 'Symbol')
withfactory.SubFactory('some.module.Symbol')
- Replace
factory.InfiniteIterator(iterable)
withfactory.Iterator(iterable)
- Replace
@factory.post_generation()
with@factory.post_generation
- Replace
factory.set_building_function(SomeFactory, building_function)
with an override of the~factory.Factory._build
method ofSomeFactory
- Replace
factory.set_creation_function(SomeFactory, creation_function)
with an override of the~factory.Factory._create
method ofSomeFactory
New:
- Add
~factory.CircularSubFactory
to solve circular dependencies between factories
Bugfix:
- Fix
~factory.PostGenerationDeclaration
and derived classes.
New:
- Add
~factory.use_strategy
decorator to override a~factory.Factory
's default strategy- Improve test running (tox, python2.6/2.7)
- Introduce
~factory.PostGeneration
and~factory.RelatedFactory
Bugfix:
- Fix packaging rules
New:
- Add
~factory.Iterator
and~factory.InfiniteIterator
for~factory.Factory
attribute declarations.- Provide
~factory.Factory.generate
and~factory.Factory.simple_generate
, that allow specifying the instantiation strategy directly. Also provides~factory.Factory.generate_batch
and~factory.Factory.simple_generate_batch
.
New:
- Add
~factory.Factory.build_batch
,~factory.Factory.create_batch
and~factory.Factory.stub_batch
, to instantiate factories in batch
New:
- Improve the
~factory.SelfAttribute
syntax to fetch sub-attributes using thefoo.bar
syntax;- Add
~factory.ContainerAttribute
to fetch attributes from the container of a~factory.SubFactory
.- Provide the
~factory.make_factory
helper:MyClassFactory = make_factory(MyClass, x=3, y=4)
- Add
~factory.build
,~factory.create
,~factory.stub
helpers
Bugfix:
- Allow classmethod/staticmethod on factories
Deprecation:
- Auto-discovery of
~factory.Factory.FACTORY_FOR
based on class name is now deprecated
New:
- Improve the algorithm for populating a
~factory.Factory
attributes dict- Add
python setup.py test
command to run the test suite- Allow custom build functions
- Introduce
~factory.MOGO_BUILD
build function- Add support for inheriting from multiple
~factory.Factory
- Base
~factory.Factory
classes can now be declaredabstract <factory.Factory.ABSTRACT_FACTORY>
.- Provide
~factory.django.DjangoModelFactory
, whose~factory.Sequence
counter starts at the next free database id- Introduce
~factory.SelfAttribute
, a shortcut forfactory.LazyAttribute(lambda o: o.foo.bar.baz
.
Bugfix:
- Handle nested
~factory.SubFactory
- Share sequence counter between parent and subclasses
- Fix
~factory.SubFactory
/~factory.Sequence
interferences
New:
- Introduce
~factory.SubFactory
New:
- Allow
~factory.Factory
inheritance- Improve handling of custom build/create functions
Bugfix:
- Fix concurrency between
~factory.LazyAttribute
and~factory.Sequence
New:
- First version of factory_boy
- Initial version by Mark Sandstrom (2010)
- Developed by Raphaël Barrois since 2011