File: test_example_7.py

package info (click to toggle)
python-polyfactory 2.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 103; sh: 37
file content (28 lines) | stat: -rw-r--r-- 614 bytes parent folder | download
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)