ChangeLog

2.9.3 (unreleased)

  • Nothing changed yet.

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:

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 the Trait feature).
  • 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.

2.8.1 (2016-12-17)

Bugfix:

  • Fix packaging issues.

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:

Removed:

2.6.1 (2016-02-10)

New:

2.6.0 (2015-10-20)

New:

  • Add factory.FactoryOptions.rename to help handle conflicting names (issue #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.e factory.Iterator(models.MyThingy.objects.all())).
  • Simplify imports for ORM layers, now available through a simple factory import, at factory.alchemy.SQLAlchemyModelFactory / factory.django.DjangoModelFactory / factory.mongoengine.MongoEngineFactory.

Bugfix:

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:

2.5.0 (2015-03-26)

New:

Bugfix:

Deprecation:

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 occurences; 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:

Deprecation:

2.3.1 (2014-01-22)

Bugfix:

2.3.0 (2013-12-25)

New:

2.2.1 (2013-09-24)

Bugfix:

  • Fixed sequence counter for DjangoModelFactory when a factory inherits from another factory relating to an abstract model.

2.2.0 (2013-09-24)

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:

2.1.2 (2013-08-14)

New:

  • The ABSTRACT_FACTORY keyword is now optional, and automatically set to True if neither the Factory subclass nor its parent declare the FACTORY_FOR attribute (issue #74)

2.1.1 (2013-07-02)

Bugfix:

  • Properly retrieve the color keyword argument passed to ImageField

2.1.0 (2013-06-26)

New:

Bugfix

Deprecation:

2.0.2 (2013-04-16)

New:

  • When FACTORY_DJANGO_GET_OR_CREATE is empty, use Model.objects.create() instead of Model.objects.get_or_create.

2.0.1 (2013-04-16)

New:

  • Don’t push defaults to get_or_create when FACTORY_DJANGO_GET_OR_CREATE is 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 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()

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

Pending deprecation

The following features have been deprecated and will be removed in an upcoming release.

  • Declarations:
    • InfiniteIterator is deprecated in favor of Iterator
    • CircularSubFactory is deprecated in favor of SubFactory
    • The extract_prefix argument to post_generation() is now deprecated
  • Factory:
    • Usage of set_creation_function() and set_building_function() are now deprecated
    • Implicit associated class discovery is no longer supported, you must set the FACTORY_FOR attribute on all Factory subclasses

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_FOR attribute pointing to the target class to each Factory, 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') with factory.SubFactory('some.module.Symbol')
  • Replace factory.InfiniteIterator(iterable) with factory.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 of SomeFactory
  • Replace factory.set_creation_function(SomeFactory, creation_function) with an override of the _create() method of SomeFactory

1.2.0 (2012-09-08)

New:

  • Add CircularSubFactory to solve circular dependencies between factories

1.1.5 (2012-07-09)

Bugfix:

  • Fix PostGenerationDeclaration and derived classes.

1.1.4 (2012-06-19)

New:

1.1.3 (2012-03-09)

Bugfix:

  • Fix packaging rules

1.1.2 (2012-02-25)

New:

1.1.1 (2012-02-24)

New:

1.1.0 (2012-02-24)

New:

Bugfix:

  • Allow classmethod/staticmethod on factories

Deprecation:

  • Auto-discovery of FACTORY_FOR based on class name is now deprecated

1.0.4 (2011-12-21)

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:

1.0.2 (2011-05-16)

New:

1.0.1 (2011-05-13)

New:

  • Allow Factory inheritance
  • Improve handling of custom build/create functions

Bugfix:

1.0.0 (2010-08-22)

New:

  • First version of factory_boy

Credits

  • Initial version by Mark Sandstrom (2010)
  • Developed by Raphaël Barrois since 2011