{"id":9504,"library":"autofaker","title":"autofaker","description":"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.","status":"active","version":"1.0.22","language":"en","source_language":"en","source_url":"https://github.com/christianhelle/autofaker","tags":["testing","unit-testing","faker","mocking","test-data","dataclasses"],"install":[{"cmd":"pip install autofaker","lang":"bash","label":"Latest version"}],"dependencies":[],"imports":[{"note":"The primary entry point is the 'Fake' function. Direct import is the recommended pattern.","wrong":"import autofaker; autofaker.Fake()","symbol":"Fake","correct":"from autofaker import Fake"}],"quickstart":{"code":"from autofaker import Fake\nfrom dataclasses import dataclass\nimport datetime\n\n@dataclass\nclass Product:\n    name: str\n    price: float\n    is_available: bool\n\n@dataclass\nclass Customer:\n    customer_id: str\n    name: str\n    email: str\n    age: int\n    registration_date: datetime.date\n    products_bought: list[Product]\n\n# Generate a fake instance of the Customer class\nfake_customer = Fake(Customer)\nprint(f\"Fake Customer Name: {fake_customer.name}\")\nprint(f\"Fake Customer Email: {fake_customer.email}\")\n\n# Generate a fake string\nfake_string = Fake(str)\nprint(f\"Fake String: {fake_string}\")\n\n# Generate a fake integer\nfake_int = Fake(int)\nprint(f\"Fake Integer: {fake_int}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always provide explicit type hints for class attributes that you expect autofaker to populate. For example, `name: str` instead of `name`.","message":"autofaker relies heavily on type hints to generate meaningful data for class attributes. If type hints are missing, especially for custom classes or complex structures, autofaker might not be able to infer the desired type or might default to `None`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"When dealing with `default_factory` in dataclasses, be aware that it will take precedence over autofaker's generation for that specific field. If you want autofaker to handle the default value generation, ensure your `default_factory` does not conflict or explicitly uses `Fake()` within it.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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.","message":"While autofaker supports nested classes, excessively deep or mutually recursive class definitions can lead to `RecursionError`. The library does not implement infinite recursion protection for all complex scenarios.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure that the argument passed to `Fake()` is a valid type (e.g., `str`, `int`, `MyClass`) and not `None`. Double-check type hints in classes.","cause":"The `Fake` function was called with `None` as the type argument, or an unresolvable type hint that defaults to `None`.","error":"TypeError: Parameter 'obj_type' cannot be None"},{"fix":"Change your import statement to `from autofaker import Fake` to directly import the `Fake` function, or explicitly call `autofaker.Fake()` if you prefer the module import.","cause":"This usually means you're trying to access `autofaker.Fake` after `import autofaker` instead of `from autofaker import Fake`.","error":"AttributeError: module 'autofaker' has no attribute 'Fake'"},{"fix":"Add explicit type hints to all fields in your class, especially required ones, to help autofaker infer how to populate them. For example, `field_name: str`.","cause":"This error can occur when trying to `Fake()` a class that has mandatory constructor arguments without default values, and autofaker cannot infer how to create them (e.g., non-type-hinted arguments or complex custom types).","error":"TypeError: __init__() missing 1 required positional argument: 'field_name'"}]}