ChangeLog¶
2.10.0 (2018-01-28)¶
Bugfix:
- issue #443: Don’t crash when calling
factory.Iterator.reset()on a brand new iterator.
New:
- issue #397: Allow a
factory.Maybeto contain aPostGenerationDeclaration. This also applies tofactory.Trait, since they use afactory.Maybedeclaration internally.
2.9.2 (2017-08-03)¶
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.
2.9.1 (2017-08-02)¶
Bugfix:
- Fix packaging issues (see https://github.com/zestsoftware/zest.releaser/issues/212)
- Don’t crash when debugging PostGenerationDeclaration
2.9.0 (2017-07-30)¶
This version brings massive changes to the core engine, thus reducing the number of corner cases and weird behaviourrs.
New:
- issue #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 theTraitfeature).PostGenerationMethodCallonly 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.
2.8.0 (2016-12-17)¶
New:
- issue #240: Call post-generation declarations in the order they were declared, thanks to Oleg Pidsadnyi.
- issue #309: Provide new options for SQLAlchemy session persistence
Bugfix:
- issue #334: Adjust for the package change in
faker
2.7.0 (2016-04-19)¶
New:
- issue #267: Add
factory.LazyFunctionto remove unneeded lambda parameters, thanks to Hervé Cauwelier.- issue #251: Add parameterized factories and
traits- issue #256, issue #292: Improve error messages in corner cases
Removed:
- issue #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.
2.6.1 (2016-02-10)¶
New:
- issue #262: Allow optional forced flush on SQLAlchemy, courtesy of Minjung.
2.6.0 (2015-10-20)¶
New:
- Add
factory.FactoryOptions.renameto help handle conflicting names (issue #206)- Add support for random-yet-realistic values through fake-factory, through the
factory.Fakerclass.factory.Iteratorno 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
factoryimport, atfactory.alchemy.SQLAlchemyModelFactory/factory.django.DjangoModelFactory/factory.mongoengine.MongoEngineFactory.
Bugfix:
- issue #201: Properly handle custom Django managers when dealing with abstract Django models.
- issue #212: Fix
factory.django.mute_signals()to handle Django’s signal caching- issue #228: Don’t load
django.apps.apps.get_model()until required- issue #219: Stop using
mogo.model.Model.new(), deprecated 4 years ago.
2.5.2 (2015-04-21)¶
Bugfix:
- Add support for Django 1.7/1.8
- Add support for mongoengine>=0.9.0 / pymongo>=2.1
2.5.1 (2015-03-27)¶
Bugfix:
- Respect custom managers in
DjangoModelFactory(see issue #192)- Allow passing declarations (e.g
Sequence) as parameters toFileFieldandImageField.
2.5.0 (2015-03-26)¶
New:
- Add support for getting/setting
factory.fuzzy’s random state (see issue #175, issue #185).- Support lazy evaluation of iterables in
factory.fuzzy.FuzzyChoice(see issue #184).- Support non-default databases at the factory level (see issue #171)
- Make
factory.django.FileFieldandfactory.django.ImageFieldnon-post_generation, i.e normal fields also available insave()(see issue #141).
Bugfix:
- Avoid issues when using
factory.django.mute_signals()on a base factory class (see issue #183).- Fix limitations of
factory.StubFactory, that can now usefactory.SubFactoryand co (see issue #131).
Deprecation:
- Remove deprecated features from 2.4.0 (2014-06-21)
- Remove the auto-magical sequence setup (based on the latest primary key value in the database) for Django and SQLAlchemy; this relates to issues issue #170, issue #153, issue #111, issue #103, issue #92, issue #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.
Upgrading¶
Warning
Version 2.5.0 removes features that were marked as deprecated in 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 .
2.4.1 (2014-06-23)¶
Bugfix:
- Fix overriding deeply inherited attributes (set in one factory, overridden in a subclass, used in a sub-sub-class).
2.4.0 (2014-06-21)¶
New:
- Add support for
factory.fuzzy.FuzzyInteger.step, thanks to ilya-pirogov (issue #120)- Add
mute_signals()decorator to temporarily disable some signals, thanks to ilya-pirogov (issue #122)- Add
FuzzyFloat(issue #124)- Declare target model and other non-declaration fields in a
class Metasection.
Deprecation:
Use of
FACTORY_FORand otherFACTORYclass-level attributes is deprecated and will be removed in 2.5. Those attributes should now declared within theclass Metaattribute:For
factory.Factory:
- Rename
FACTORY_FORtomodel- Rename
ABSTRACT_FACTORYtoabstract- Rename
FACTORY_STRATEGYtostrategy- Rename
FACTORY_ARG_PARAMETERStoinline_args- Rename
FACTORY_HIDDEN_ARGStoexcludeFor
factory.django.DjangoModelFactory:
- Rename
FACTORY_DJANGO_GET_OR_CREATEtodjango_get_or_createFor
factory.alchemy.SQLAlchemyModelFactory:
- Rename
FACTORY_SESSIONtosqlalchemy_session
2.3.1 (2014-01-22)¶
Bugfix:
- Fix badly written assert containing state-changing code, spotted by chsigi (issue #126)
- Don’t crash when handling objects whose __repr__ is non-pure-ascii bytes on Py2, discovered by mbertheau (issue #123) and strycore (issue #127)
2.3.0 (2013-12-25)¶
New:
- Add
FuzzyText, thanks to jdufresne (issue #97)- Add
FuzzyDecimal, thanks to thedrow (issue #94)- Add support for
EmbeddedDocument, thanks to imiric (issue #100)
2.2.1 (2013-09-24)¶
Bugfix:
- Fixed sequence counter for
DjangoModelFactorywhen a factory inherits from another factory relating to an abstract model.
2.2.0 (2013-09-24)¶
Bugfix:
- Removed duplicated
SQLAlchemyModelFactorylurking infactory(issue #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 (issue #93)
- Properly handle nested
SubFactoryoverrides
New:
- The
DjangoModelFactorynow supports theFACTORY_FOR = 'myapp.MyModel'syntax, making it easier to shove all factories in a single module (issue #66).- Add
factory.debug()helper for easier backtrace analysis- Adding factory support for mongoengine with
MongoEngineFactory.
2.1.0 (2013-06-26)¶
New:
- Add
FuzzyDatethanks to saulshanabrook- Add
FuzzyDateTimeandFuzzyNaiveDateTime.- Add a
factory_parentattribute to theResolverpassed toLazyAttribute, in order to access fields defined in wrapping factories.- Move
DjangoModelFactoryandMogoFactoryto their own modules (factory.djangoandfactory.mogo)- Add the
reset_sequence()classmethod toFactoryto ease resetting the sequence counter for a given factory.- Add debug messages to
factorylogger.- Add a
reset()method toIterator(issue #63)- Add support for the SQLAlchemy ORM through
SQLAlchemyModelFactory(issue #64, thanks to Romain Commandé)- Add
factory.django.FileFieldandfactory.django.ImageFieldhooks for related Django model fields (issue #52)
Bugfix
- Properly handle non-integer pks in
DjangoModelFactory(issue #57).- Disable
RelatedFactorygeneration when a specific value was passed (issue #62, thanks to Gabe Koscky)
Deprecation:
- Rename
RelatedFactory’snameargument tofactory_related_name(See issue #58)
2.0.2 (2013-04-16)¶
New:
- When
FACTORY_DJANGO_GET_OR_CREATEis empty, useModel.objects.create()instead ofModel.objects.get_or_create.
2.0.1 (2013-04-16)¶
New:
- Don’t push
defaultstoget_or_createwhenFACTORY_DJANGO_GET_OR_CREATEis not set.
2.0.0 (2013-04-15)¶
New:
- Allow overriding the base factory class for
make_factory()and friends.- Add support for Python3 (Thanks to kmike and nkryptic)
- The default
typeforSequenceis nowint- Fields listed in
FACTORY_HIDDEN_ARGSwon’t be passed to the associated class’ constructor- Add support for
get_or_createinDjangoModelFactory, throughFACTORY_DJANGO_GET_OR_CREATE.- Add support for
fuzzyattribute definitions.- The
Sequencecounter can be overridden when calling a generating function- Add
DictandListdeclarations (Closes issue #18).
Removed:
- Remove associated class discovery
- Remove
InfiniteIteratorandinfinite_iterator()- Remove
CircularSubFactory- Remove
extract_prefixkwarg to post-generation hooks.- Stop defaulting to Django’s
Foo.objects.create()when “creating” instances- Remove STRATEGY_*
- Remove
set_building_function()/set_creation_function()
1.3.0 (2013-03-11)¶
Warning
This version deprecates many magic or unexplicit features that will be removed in v2.0.0.
Please read the Upgrading section, then run your
tests with python -W default to see all remaining warnings.
New¶
- Global:
- Rewrite the whole documentation
- Provide a dedicated
MogoFactorysubclass ofFactory
- The Factory class:
- Better creation/building customization hooks at
factory.Factory._build()andfactory.Factory.create() - Add support for passing non-kwarg parameters to a
Factorywrapped class throughFACTORY_ARG_PARAMETERS. - Keep the
FACTORY_FORattribute inFactoryclasses
- Better creation/building customization hooks at
- Declarations:
- Allow
SubFactoryto solve circular dependencies between factories - Enhance
SelfAttributeto handle “container” attribute fetching - Add a
gettertoIteratordeclarations - A
Iteratormay be prevented from cycling by setting itscycleargument toFalse - Allow overriding default arguments in a
PostGenerationMethodCallwhen generating an instance of the factory - An object created by a
DjangoModelFactorywill be saved again afterPostGenerationhooks execution
- Allow
Pending deprecation¶
The following features have been deprecated and will be removed in an upcoming release.
- Declarations:
InfiniteIteratoris deprecated in favor ofIteratorCircularSubFactoryis deprecated in favor ofSubFactory- The
extract_prefixargument topost_generation()is now deprecated
- Factory:
- Usage of
set_creation_function()andset_building_function()are now deprecated - Implicit associated class discovery is no longer supported, you must set the
FACTORY_FORattribute on allFactorysubclasses
- Usage of
Upgrading¶
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_FORattribute pointing to the target class to eachFactory, instead of relying on automagic associated class discovery - When using factory_boy for Django models, have each factory inherit from
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_build()method ofSomeFactory - Replace
factory.set_creation_function(SomeFactory, creation_function)with an override of the_create()method ofSomeFactory
1.1.4 (2012-06-19)¶
New:
- Add
use_strategy()decorator to override aFactory’s default strategy- Improve test running (tox, python2.6/2.7)
- Introduce
PostGenerationandRelatedFactory
1.1.2 (2012-02-25)¶
New:
- Add
IteratorandInfiniteIteratorforFactoryattribute declarations.- Provide
generate()andsimple_generate(), that allow specifying the instantiation strategy directly. Also providesgenerate_batch()andsimple_generate_batch().
1.1.1 (2012-02-24)¶
New:
- Add
build_batch(),create_batch()andstub_batch(), to instantiate factories in batch
1.1.0 (2012-02-24)¶
New:
- Improve the
SelfAttributesyntax to fetch sub-attributes using thefoo.barsyntax;- Add
ContainerAttributeto fetch attributes from the container of aSubFactory.- Provide the
make_factory()helper:MyClassFactory = make_factory(MyClass, x=3, y=4)- Add
build(),create(),stub()helpers
Bugfix:
- Allow classmethod/staticmethod on factories
Deprecation:
- Auto-discovery of
FACTORY_FORbased on class name is now deprecated
1.0.4 (2011-12-21)¶
New:
- Improve the algorithm for populating a
Factoryattributes dict- Add
python setup.py testcommand to run the test suite- Allow custom build functions
- Introduce
MOGO_BUILDbuild function- Add support for inheriting from multiple
Factory- Base
Factoryclasses can now be declaredabstract.- Provide
DjangoModelFactory, whoseSequencecounter starts at the next free database id- Introduce
SelfAttribute, a shortcut forfactory.LazyAttribute(lambda o: o.foo.bar.baz.
Bugfix:
- Handle nested
SubFactory- Share sequence counter between parent and subclasses
- Fix
SubFactory/Sequenceinterferences
1.0.1 (2011-05-13)¶
New:
- Allow
Factoryinheritance- Improve handling of custom build/create functions
Bugfix:
- Fix concurrency between
LazyAttributeandSequence
Credits¶
- Initial version by Mark Sandstrom (2010)
- Developed by Raphaël Barrois since 2011