autofaker

1.0.22 · active · verified Fri Apr 17

autofaker is a Python library designed to minimize the setup/arrange phase of unit tests by automatically generating anonymous variables for various data types and classes. It supports built-in types (int, str, float), datetime types (datetime, date), and simple, nested, or dataclasses. As of version 1.0.22, it remains actively developed with a focus on simplifying test data generation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `autofaker.Fake()` to generate instances of complex dataclasses with nested structures and built-in types, as well as standalone fake primitive values. autofaker leverages type hints to infer and generate appropriate data.

from autofaker import Fake
from dataclasses import dataclass
import datetime

@dataclass
class Product:
    name: str
    price: float
    is_available: bool

@dataclass
class Customer:
    customer_id: str
    name: str
    email: str
    age: int
    registration_date: datetime.date
    products_bought: list[Product]

# Generate a fake instance of the Customer class
fake_customer = Fake(Customer)
print(f"Fake Customer Name: {fake_customer.name}")
print(f"Fake Customer Email: {fake_customer.email}")

# Generate a fake string
fake_string = Fake(str)
print(f"Fake String: {fake_string}")

# Generate a fake integer
fake_int = Fake(int)
print(f"Fake Integer: {fake_int}")

view raw JSON →