File: test_example_3.py

package info (click to toggle)
python-polyfactory 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,976 kB
  • sloc: python: 11,113; makefile: 102; sh: 34
file content (28 lines) | stat: -rw-r--r-- 595 bytes parent folder | download | duplicates (2)
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 dataclasses import dataclass

from faker import Faker

from polyfactory.factories import DataclassFactory


@dataclass
class Person:
    name: str
    age: float
    height: float
    weight: float


class PersonFactory(DataclassFactory[Person]):
    __faker__ = Faker(locale="es_ES")

    __random_seed__ = 10

    @classmethod
    def name(cls) -> str:
        return cls.__faker__.name()


def test_setting_faker() -> None:
    # the outcome of faker deterministic because we seeded random, and it uses a spanish locale.
    assert PersonFactory.build().name == "Alejandra Romeu-Tolosa"