Factory-boy

Latest version: v3.3.1

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

Scan your dependencies

Page 4 of 8

2.6.1

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

*New:*

- :pr:`262`: Allow optional forced flush on SQLAlchemy, courtesy of `Minjung <https://github.com/Minjung>`_.

2.6.0

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

*New:*

- Add :attr:`factory.FactoryOptions.rename` to help handle conflicting names (:issue:`206`)
- Add support for random-yet-realistic values through `fake-factory <https://pypi.org/project/fake-factory/>`_,
through the :class:`factory.Faker` class.
- :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``.

*Bug fix:*

- :issue:`201`: Properly handle custom Django managers when dealing with abstract Django models.
- :issue:`212`: Fix :meth:`factory.django.mute_signals` to handle Django's signal caching
- :issue:`228`: Don't load ``django.apps.apps.get_model()`` until required
- :pr:`219`: Stop using ``mogo.model.Model.new()``, deprecated 4 years ago.

2.5.2

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

*Bug fix:*

- Add support for Django 1.7/1.8
- Add support for mongoengine>=0.9.0 / pymongo>=2.1

2.5.1

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

*Bug fix:*

- Respect custom managers in :class:`~factory.django.DjangoModelFactory` (see :issue:`192`)
- Allow passing declarations (e.g :class:`~factory.Sequence`) as parameters to :class:`~factory.django.FileField`
and :class:`~factory.django.ImageField`.

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).

Page 4 of 8

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.