Bugfix:
- Add support for Django 1.7/1.8
- Add support for mongoengine>=0.9.0 / pymongo>=2.1
Bugfix:
- Respect custom managers in DjangoModelFactory (see issue #192)
- Allow passing declarations (e.g Sequence) as parameters to FileField and ImageField.
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.FileField and factory.django.ImageField non-post_generation, i.e normal fields also available in save() (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 use factory.SubFactory and 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/rbarrois/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.
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 occurences; 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 (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 Meta section.
Deprecation:
Use of FACTORY_FOR and other FACTORY class-level attributes is deprecated and will be removed in 2.5. Those attributes should now declared within the class Meta attribute:
For factory.Factory:
- Rename FACTORY_FOR to model
- Rename FACTORY_FOR to model
- Rename ABSTRACT_FACTORY to abstract
- Rename FACTORY_STRATEGY to strategy
- Rename FACTORY_ARG_PARAMETERS to inline_args
- Rename FACTORY_HIDDEN_ARGS to exclude
For factory.django.DjangoModelFactory:
- Rename FACTORY_DJANGO_GET_OR_CREATE to django_get_or_create
For factory.alchemy.SQLAlchemyModelFactory:
- Rename FACTORY_SESSION to sqlalchemy_session
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)
New:
- Add FuzzyText, thanks to jdufresne (issue #97)
- Add FuzzyDecimal, thanks to thedrow (issue #94)
- Add support for EmbeddedDocument, thanks to imiric (issue #100)
Bugfix:
- Fixed sequence counter for DjangoModelFactory when a factory inherits from another factory relating to an abstract model.
Bugfix:
- Removed duplicated SQLAlchemyModelFactory lurking in factory (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 SubFactory overrides
New:
- The DjangoModelFactory now supports the FACTORY_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.
New:
- Add FuzzyDate thanks to saulshanabrook
- Add FuzzyDateTime and FuzzyNaiveDateTime.
- Add a factory_parent attribute to the LazyStub passed to LazyAttribute, in order to access fields defined in wrapping factories.
- Move DjangoModelFactory and MogoFactory to their own modules (factory.django and factory.mogo)
- Add the reset_sequence() classmethod to Factory to ease resetting the sequence counter for a given factory.
- Add debug messages to factory logger.
- Add a reset() method to Iterator (issue #63)
- Add support for the SQLAlchemy ORM through SQLAlchemyModelFactory (issue #64, thanks to Romain Commandé)
- Add factory.django.FileField and factory.django.ImageField hooks for related Django model fields (issue #52)
Bugfix
- Properly handle non-integer pks in DjangoModelFactory (issue #57).
- Disable RelatedFactory generation when a specific value was passed (issue #62, thanks to Gabe Koscky)
Deprecation:
- Rename RelatedFactory‘s name argument to factory_related_name (See issue #58)
New:
- When FACTORY_DJANGO_GET_OR_CREATE is empty, use Model.objects.create() instead of Model.objects.get_or_create.
New:
- Don’t push defaults to get_or_create when FACTORY_DJANGO_GET_OR_CREATE is not set.
New:
- Allow overriding the base factory class for make_factory() and friends.
- Add support for Python3 (Thanks to kmike and nkryptic)
- The default type for Sequence is now int
- Fields listed in FACTORY_HIDDEN_ARGS won’t be passed to the associated class’ constructor
- Add support for get_or_create in DjangoModelFactory, through FACTORY_DJANGO_GET_OR_CREATE.
- Add support for fuzzy attribute definitions.
- The Sequence counter can be overridden when calling a generating function
- Add Dict and List declarations (Closes issue #18).
Removed:
- Remove associated class discovery
- Remove InfiniteIterator and infinite_iterator()
- Remove CircularSubFactory
- Remove extract_prefix kwarg to post-generation hooks.
- Stop defaulting to Django’s Foo.objects.create() when “creating” instances
- Remove STRATEGY_*
- Remove set_building_function() / set_creation_function()
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.
The following features have been deprecated and will be removed in an upcoming release.
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:
New:
- Add use_strategy() decorator to override a Factory‘s default strategy
- Improve test running (tox, python2.6/2.7)
- Introduce PostGeneration and RelatedFactory
New:
- Add Iterator and InfiniteIterator for Factory attribute declarations.
- Provide generate() and simple_generate(), that allow specifying the instantiation strategy directly. Also provides generate_batch() and simple_generate_batch().
New:
- Add build_batch(), create_batch() and stub_batch(), to instantiate factories in batch
New:
- Improve the SelfAttribute syntax to fetch sub-attributes using the foo.bar syntax;
- Add ContainerAttribute to fetch attributes from the container of a SubFactory.
- 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_FOR based on class name is now deprecated
New:
- Improve the algorithm for populating a Factory attributes dict
- Add python setup.py test command to run the test suite
- Allow custom build functions
- Introduce MOGO_BUILD build function
- Add support for inheriting from multiple Factory
- Base Factory classes can now be declared abstract.
- Provide DjangoModelFactory, whose Sequence counter starts at the next free database id
- Introduce SelfAttribute, a shortcut for factory.LazyAttribute(lambda o: o.foo.bar.baz.
Bugfix:
- Handle nested SubFactory
- Share sequence counter between parent and subclasses
- Fix SubFactory / Sequence interferences
New:
- Allow Factory inheritance
- Improve handling of custom build/create functions
Bugfix:
- Fix concurrency between LazyAttribute and Sequence