freshcrate
Home > Frameworks > factory-boy

factory-boy

A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby.

Description

factory_boy =========== .. image:: https://github.com/FactoryBoy/factory_boy/workflows/Test/badge.svg :target: https://github.com/FactoryBoy/factory_boy/actions?query=workflow%3ATest .. image:: https://github.com/FactoryBoy/factory_boy/workflows/Check/badge.svg :target: https://github.com/FactoryBoy/factory_boy/actions?query=workflow%3ACheck .. image:: https://img.shields.io/pypi/v/factory_boy.svg :target: https://factoryboy.readthedocs.io/en/latest/changelog.html :alt: Latest Version .. image:: https://img.shields.io/pypi/pyversions/factory_boy.svg :target: https://pypi.org/project/factory-boy/ :alt: Supported Python versions .. image:: https://img.shields.io/pypi/wheel/factory_boy.svg :target: https://pypi.org/project/factory-boy/ :alt: Wheel status .. image:: https://img.shields.io/pypi/l/factory_boy.svg :target: https://github.com/FactoryBoy/factory_boy/blob/master/LICENSE :alt: License factory_boy is a fixtures replacement based on thoughtbot's `factory_bot <https://github.com/thoughtbot/factory_bot>`_. As a fixtures replacement tool, it aims to replace static, hard to maintain fixtures with easy-to-use factories for complex objects. Instead of building an exhaustive test setup with every possible combination of corner cases, ``factory_boy`` allows you to use objects customized for the current test, while only declaring the test-specific fields: .. code-block:: python class FooTests(unittest.TestCase): def test_with_factory_boy(self): # We need a 200€, paid order, shipping to australia, for a VIP customer order = OrderFactory( amount=200, status='PAID', customer__is_vip=True, address__country='AU', ) # Run the tests here def test_without_factory_boy(self): address = Address( street="42 fubar street", zipcode="42Z42", city="Sydney", country="AU", ) customer = Customer( first_name="John", last_name="Doe", phone="+1234", email="john.doe@example.org", active=True, is_vip=True, address=address, ) # etc. factory_boy is designed to work well with various ORMs (Django, MongoDB, SQLAlchemy), and can easily be extended for other libraries. Its main features include: - Straightforward declarative syntax - Chaining factory calls while retaining the global context - Support for multiple build strategies (saved/unsaved instances, stubbed objects) - Multiple factories per class support, including inheritance Links ----- * Documentation: https://factoryboy.readthedocs.io/ * Repository: https://github.com/FactoryBoy/factory_boy * Package: https://pypi.org/project/factory-boy/ * Mailing-list: `factoryboy@googlegroups.com <mailto:factoryboy@googlegroups.com>`_ | https://groups.google.com/forum/#!forum/factoryboy Download -------- PyPI: https://pypi.org/project/factory-boy/ .. code-block:: sh $ pip install factory_boy Source: https://github.com/FactoryBoy/factory_boy/ .. code-block:: sh $ git clone git://github.com/FactoryBoy/factory_boy/ $ python setup.py install Usage ----- .. note:: This section provides a quick summary of factory_boy features. A more detailed listing is available in the full documentation. Defining factories """""""""""""""""" Factories declare a set of attributes used to instantiate a Python object. The class of the object must be defined in the ``model`` field of a ``class Meta:`` attribute: .. code-block:: python import factory from . import models class UserFactory(factory.Factory): class Meta: model = models.User first_name = 'John' last_name = 'Doe' admin = False # Another, different, factory for the same object class AdminFactory(factory.Factory): class Meta: model = models.User first_name = 'Admin' last_name = 'User' admin = True ORM integration """"""""""""""" factory_boy integration with Object Relational Mapping (ORM) tools is provided through specific ``factory.Factory`` subclasses: * Django, with ``factory.django.DjangoModelFactory`` * Mogo, with ``factory.mogo.MogoFactory`` * MongoEngine, with ``factory.mongoengine.MongoEngineFactory`` * SQLAlchemy, with ``factory.alchemy.SQLAlchemyModelFactory`` More details can be found in the ORM section. Using factories """"""""""""""" factory_boy supports several different instantiation strategies: build, create, and stub: .. code-block:: python # Returns a User instance that's not saved user = UserFactory.build() # Returns a saved User instance. # UserFactory must subclass an ORM base class, such as DjangoModelFactory. user = UserFactory.create()

Release History

VersionChangesUrgencyDate
3.3.3Imported from PyPI (3.3.3)Low4/21/2026
v2.9.0Tag v2.9.0Low7/30/2017
v2.8.1Tag v2.8.1Low12/17/2016
v2.8.0Tag v2.8.0Low12/17/2016
v2.7.0Tag v2.7.0Low4/19/2016
v2.6.1Tag v2.6.1Low2/10/2016
v2.6.0Tag v2.6.0Low10/20/2015
v2.5.2Tag v2.5.2Low4/21/2015
v2.5.1Tag v2.5.1Low3/27/2015
v2.5.0Tag v2.5.0Low3/26/2015
v2.4.1Tag v2.4.1Low6/23/2014
v2.4.0Tag v2.4.0Low6/21/2014
v2.3.1Tag v2.3.1Low1/22/2014
v2.3.0Tag v2.3.0Low12/25/2013
v2.2.1Tag v2.2.1Low9/25/2013
v2.2.0Tag v2.2.0Low9/24/2013
v2.1.2Tag v2.1.2Low8/14/2013
v2.1.1Tag v2.1.1Low7/2/2013
v2.1.0Tag v2.1.0Low6/26/2013
v2.0.2Tag v2.0.2Low4/16/2013
v2.0.1Tag v2.0.1Low4/16/2013

Dependencies & License Audit

Loading dependencies...

Similar Packages

dependency-injectorDependency injection framework for Python4.49.0
pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2