File: test_example_1.py

package info (click to toggle)
python-polyfactory 2.22.2-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 102; sh: 38
file content (26 lines) | stat: -rw-r--r-- 657 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
from dataclasses import dataclass

from polyfactory.factories import DataclassFactory


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


class PersonFactory(DataclassFactory[Person]):
    __random_seed__ = 1

    @classmethod
    def name(cls) -> str:
        return cls.__random__.choice(["John", "Alice", "George"])


def test_random_seed() -> None:
    # the outcome of 'factory.__random__.choice' is deterministic, because Random has been seeded with a set value.
    assert PersonFactory.build().name == "John"
    assert PersonFactory.build().name == "George"
    assert PersonFactory.build().name == "John"