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.
pip install autofakerVerified import paths — ran on the pinned version, not inferred.
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.
Always provide explicit type hints for class attributes that you expect autofaker to populate. For example, `name: str` instead of `name`.
If `default_factory` is used and you still want autofaker to generate the value, embed `Fake()` in the factory, e.g., `field(default_factory=lambda: Fake(str))` or remove the `default_factory` entirely if autofaker should generate it based on the type hint.
Design your classes to avoid overly deep or circular dependencies when using autofaker. For testing, consider faking parts of the deeper structure manually or simplifying the test subject's dependencies.
No dependency data recorded yet.