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.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
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
- Declarative factories: Defaults defined once, overridden per test.
- ORM integration: Django, SQLAlchemy and MongoEngine factories.
- Faker support: Realistic names, emails and addresses.
- Relationships and traits: SubFactory, RelatedFactory and named traits.
Pros
- Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 1 January 2026.
- Community: About 3,800 GitHub stars.
Cons
- Hidden data creation: SubFactories can create more database rows than expected, slowing tests.
- Slower release cadence: Recent development is quieter than some testing libraries.
Usage and Links (Example)
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.
Recommended for?
- Django and SQLAlchemy projects with lots of model-heavy tests.
- 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.
- Ppytestpytest is the usual Python test runner: plain asserts, fixtures, parametrization, and a large plugin set.Compare with factory_boy
Ffactory_botfactory_bot is thoughtbot's MIT-licensed Ruby library for setting up test data with factories, sequences, traits and associations, used with RSpec, Minitest and Rails via factory_bot_rails.Compare with factory_boy
PPython unittestunittest is Python's built-in xUnit-style testing framework, with TestCase classes, fixtures, test discovery, subtests, async test cases and the unittest.mock library, available in every Python install.Compare with factory_boy
HHypothesisHypothesis is the MPL-2.0 property-based testing library for Python: describe the range of inputs, let it generate cases including edge cases, and get the simplest failing example when a property breaks.Compare with factory_boy
Rresponsesresponses is an Apache-2.0 Python library from Sentry for mocking the Requests HTTP library, letting tests register fake responses, match request details and assert on calls.Compare with factory_boy
VVCR.pyVCR.py is an MIT-licensed Python library, ported from Ruby's VCR, that records HTTP interactions to cassette files and replays them in later test runs for fast, deterministic, offline tests.Compare with factory_boy