finds.dev← search

// the find

FactoryBoy/factory_boy

★ 3,799 · Python · MIT · updated Jan 2026

A test fixtures replacement for Python

factory_boy is a Python test fixture library that replaces static fixture files with declarative factory classes. It integrates directly with Django ORM, SQLAlchemy, and MongoEngine, so you get real model instances with minimal boilerplate. Aimed at Python developers who've outgrown hand-rolled setUp() methods or YAML fixtures.

SubFactory and double-underscore traversal (customer__is_vip=True) let you set nested object attributes inline without juggling intermediate objects. The build/create/stub strategy separation is clean — build() skips DB writes when you don't need them, which keeps unit tests fast. faker integration via factory.Faker is first-class, not bolted on, and seeding via factory.random.reseed_random() makes randomized data reproducible in CI. The SQLAlchemy integration correctly threads scoped sessions through SubFactory chains, which is the part that usually breaks in homegrown solutions.

The fuzzy module is soft-deprecated in favor of faker, but it's still there and undocumented newcomers will find it and use it. Debugging deep factory chains is painful — the debug() context manager helps but the output is dense and hard to read. AsyncIO support is bolted on and incomplete; async Django views and SQLAlchemy async sessions require workarounds that aren't covered in the main docs. MongoEngine support lags behind Django/SQLAlchemy — the mongoengine module feels like it was added to check a box and hasn't kept pace with the main library.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →