Factory-boy

Latest version: v3.3.3

Safety actively analyzes 722460 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 9

2.5.0

------------------

*New:*

- Add support for getting/setting :mod:`factory.fuzzy`'s random state (see :issue:`175`, :issue:`185`).
- Support lazy evaluation of iterables in :class:`factory.fuzzy.FuzzyChoice` (see :issue:`184`).
- Support non-default databases at the factory level (see :issue:`171`)
- Make :class:`factory.django.FileField` and :class:`factory.django.ImageField` non-post_generation, i.e normal fields also available in ``save()`` (see :issue:`141`).

*Bug fix:*

- Avoid issues when using :meth:`factory.django.mute_signals` on a base factory class (see :issue:`183`).
- Fix limitations of :class:`factory.StubFactory`, that can now use :class:`factory.SubFactory` and co (see :issue:`131`).


*Deprecation:*

- Remove deprecated features from :ref:`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 :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 :ref:`v2.4.0 <v2.4.0>`.

All ``FACTORY_*``-style attributes are now declared in a ``class Meta:`` section:

.. code-block:: python

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:

.. code-block:: sh

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

------------------

*Bug fix:*

- Fix overriding deeply inherited attributes (set in one factory, overridden in a subclass, used in a sub-sub-class).

2.4.0

------------------

*New:*

- Add support for :attr:`factory.fuzzy.FuzzyInteger.step`, thanks to `ilya-pirogov <https://github.com/ilya-pirogov>`_ (:pr:`120`)
- Add :meth:`~factory.django.mute_signals` decorator to temporarily disable some signals, thanks to `ilya-pirogov <https://github.com/ilya-pirogov>`_ (:pr:`122`)
- Add :class:`~factory.fuzzy.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:`class Meta <factory.FactoryOptions>` attribute:

For :class:`factory.Factory`:

* Rename ``factory.Factory.FACTORY_FOR`` to :attr:`~factory.FactoryOptions.model`
* Rename ``factory.Factory.ABSTRACT_FACTORY`` to :attr:`~factory.FactoryOptions.abstract`
* Rename ``factory.Factory.FACTORY_STRATEGY`` to :attr:`~factory.FactoryOptions.strategy`
* Rename ``factory.Factory.FACTORY_ARG_PARAMETERS`` to :attr:`~factory.FactoryOptions.inline_args`
* Rename ``factory.Factory.FACTORY_HIDDEN_ARGS`` to :attr:`~factory.FactoryOptions.exclude`

For :class:`factory.django.DjangoModelFactory`:

* Rename ``factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`` to :attr:`~factory.django.DjangoOptions.django_get_or_create`

For :class:`factory.alchemy.SQLAlchemyModelFactory`:

* Rename ``factory.alchemy.SQLAlchemyModelFactory.FACTORY_SESSION`` to :attr:`~factory.alchemy.SQLAlchemyOptions.sqlalchemy_session`

2.3.1

------------------

*Bug fix:*

- Fix badly written assert containing state-changing code, spotted by ``chsigi`` (:pr:`126`)
- Don't crash when handling objects whose ``__repr__`` is non-pure-ASCII bytes on Python 2,
discovered by `mbertheau <https://github.com/mbertheau>`_ (:issue:`123`) and `strycore <https://github.com/strycore>`_ (:pr:`127`)

2.3.0

------------------

*New:*

- Add :class:`~factory.fuzzy.FuzzyText`, thanks to `jdufresne <https://github.com/jdufresne>`_ (:pr:`97`)
- Add :class:`~factory.fuzzy.FuzzyDecimal`, thanks to `thedrow <https://github.com/thedrow>`_ (:pr:`94`)
- Add support for :class:`~mongoengine.EmbeddedDocument`, thanks to `imiric <https://github.com/imiric>`_ (:pr:`100`)

2.2.1

------------------

*Bug fix:*

- Fixed sequence counter for :class:`~factory.django.DjangoModelFactory` when a factory
inherits from another factory relating to an abstract model.

Page 5 of 9

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.