CheckOps home

Tools directory

F

CheckOps

factory_boy

factory_boy is an MIT-licensed test fixtures replacement for Python, inspired by thoughtbot's factory_bot, that builds test objects and ORM records for Django, SQLAlchemy and MongoEngine with Faker integration.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

factory_boy is a fixtures replacement based on thoughtbot’s factory_bot for Ruby. Instead of maintaining static fixture files or building complex objects by hand in every test, you declare a factory once and generate objects with sensible defaults, overriding only the attributes a test cares about.

Factories declare attributes with factory.Sequence for unique values, factory.LazyAttribute for derived values, factory.SubFactory for related objects, factory.Faker for realistic fake data (using the Faker library) and traits for named variations. Build strategies include build() (unsaved), create() (saved via the ORM) and stub(), plus batch helpers. ORM integrations include factory.django.DjangoModelFactory, factory.alchemy.SQLAlchemyModelFactory and factory.mongoengine.MongoEngineFactory. With pytest, the pytest-factoryboy plugin can register factories as fixtures. The repository has about 3,800 stars; there are no GitHub releases, and versions are published on PyPI.

The source code is at FactoryBoy/factory_boy on GitHub under the MIT licence, with about 3,800 stars; the most recent commit was on 1 January 2026.

Features

  1. Declarative factories: Defaults defined once, overridden per test.
  2. ORM integration: Django, SQLAlchemy and MongoEngine factories.
  3. Faker support: Realistic names, emails and addresses.
  4. Relationships and traits: SubFactory, RelatedFactory and named traits.

Pros

  1. Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 1 January 2026.
  3. Community: About 3,800 GitHub stars.

Cons

  1. Hidden data creation: SubFactories can create more database rows than expected, slowing tests.
  2. Slower release cadence: Recent development is quieter than some testing libraries.
import factory
from myapp.models import User, Order

class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User
    username = factory.Sequence(lambda n: f"user{n}")
    email = factory.Faker("email")

class OrderFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Order
    user = factory.SubFactory(UserFactory)
    total = 100

def test_order_belongs_to_user(db):
    order = OrderFactory(total=250)
    assert order.user.orders.count() == 1

Resources:

Pricing

factory_boy is free and open source under the MIT licence.

  1. Django and SQLAlchemy projects with lots of model-heavy tests.
  2. Teams replacing brittle static fixtures.

Conclusion

factory_boy is the standard way to build test data in Python, making tests shorter, clearer and easier to maintain.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with factory_boy side by side.