1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
from datetime import date, datetime
from typing import Any, Dict, List, Union
from uuid import UUID
import attrs
from polyfactory.factories.attrs_factory import AttrsFactory
@attrs.define
class Person:
id: UUID
name: str
hobbies: List[str]
age: Union[float, int]
# an aliased variable
birthday: Union[datetime, date] = attrs.field(alias="date_of_birth")
# a "private" variable
_assets: List[Dict[str, Dict[str, Any]]]
class PersonFactory(AttrsFactory[Person]): ...
def test_person_factory() -> None:
person = PersonFactory.build()
assert isinstance(person, Person)
|