factory_boy

Python test fixture replacement library. factory_boy provides factories for creating test objects with realistic data. Instead of manually constructing test objects in every test, define a Factory class once and generate objects with random or specified data. Integrates with Django ORM, SQLAlchemy, and Mongoengine. Replaces fragile fixtures with programmatic, flexible object generation.

Evaluated Mar 06, 2026 (0d ago) v3.3+
Homepage ↗ Repo ↗ Developer Tools python testing fixtures factories faker django sqlalchemy mocking
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
98
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
80
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
90
Secret Handling
95

Testing library — no network access. Test data should never contain real PII. Faker generates fake but realistic-looking data.

⚡ Reliability

Uptime/SLA
95
Version Stability
90
Breaking Changes
88
Error Recovery
85
AF Security Reliability

Best When

You have Django or SQLAlchemy models and want to generate realistic test objects with relationships without writing repetitive fixture setup code.

Avoid When

Your tests don't involve ORM models or you need extremely high-volume test data generation — raw factories have per-object overhead.

Use Cases

  • Generate realistic test data for agent data model tests without manually creating every field
  • Create test fixtures for database-backed agent tests with SQLAlchemy or Django ORM integration
  • Build parameterized test factories for agent input validation tests with controlled variation
  • Use SubFactory to generate related objects in agent integration tests with proper relationship setup
  • Combine with Faker for realistic-looking test data (names, emails, addresses) in agent test suites

Not For

  • Non-ORM test data — for plain Python objects without ORM, dataclasses or pytest fixtures may be simpler
  • Production data generation — factory_boy is a testing tool, not for seeding production databases
  • Performance testing with millions of records — factories have overhead; use bulk_create or CSV imports for large datasets

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no authentication.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Completely free and open source.

Agent Metadata

Pagination
none
Idempotent
Partial
Retry Guidance
Not documented

Known Gotchas

  • create() vs build() vs stub() — create() hits the database, build() creates Python objects only; using create() in unit tests that don't need DB access slows tests significantly
  • Sequence values are global by default — parallel test execution (pytest-xdist) can cause sequence collisions; use factory.reset_sequence() or unique constraints
  • SubFactory creates parent objects every time — if creating 100 child objects, 100 parent objects are also created unless explicitly reused with a single parent instance
  • Lazy attributes (LazyAttribute, LazyFunction) are evaluated per instance — referencing other fields in LazyAttribute requires using the obj parameter correctly
  • Django's test database must be active before factory.create() is called — factories in pytest conftest setup may execute before the test database is initialized
  • Factory inheritance works but Meta.model must be set on each concrete factory — abstract factories without Meta.model raise CyclicDefinitionError

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for factory_boy.

$99

Scores are editorial opinions as of 2026-03-06.

5215
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered