factorio: A fixtures replacement tool
factorio is a fixtures replacement tool that's been heavily influenced by
factory boy. It's intention is to hide irrelevant fields when
writing a test.
Even though it's been designed to play well with various ORMs, it tries to avoid any interaction with a database, as the saving/retrieving an object shouldn't be the responsibility of the factory.
Under the hood it uses faker to create realistic values for each field.
Quick Start
from dataclasses import dataclass
from factorio import fields
from factorio.factories import Factory
@dataclass
class User:
name: str
email: str
age: int
class UserFactory(Factory[User]):
name = fields.TextField("name")
email = fields.TextField("email")
age = fields.IntegerField(min_value=18, max_value=65)
user = UserFactory.build()
# user.name might be "Sarah Johnson"
# user.email might be "sarah.johnson@example.com"
# user.age might be 34
Key Features
- 🎯 Explicit Object Creation: Requires
.build()method for clarity and safety - 🚫 No Database Interaction: Factories generate data, tests handle persistence
- ✨ Realistic Data: Powered by Faker for lifelike test data
- 🔧 20+ Field Types: From primitives to collections and nested factories
- 🎨 Flexible Overrides: Override fields with values or dynamic field instances
- 📦 ORM Agnostic: Works with dataclasses, Pydantic, SQLAlchemy, and more
- 🛡️ Type Safe: Full type hints and mypy support
Documentation
- Installation Guide - Get started with factorio
- Usage Guide - Basic to advanced usage patterns
- Field Reference - Complete API reference for all field types
- Factory API - Factory class documentation
- Integration Guides - SQLAlchemy, Pydantic, and dataclasses
- Cookbook - Common patterns and recipes
- Advanced Guide - Advanced techniques and optimizations
- Changelog - Version history and changes