Skip to content

factorio: A fixtures replacement tool

build lint tests license codecov readthedocs pypi downloads build automation: yam Lint: ruff

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