How to disable randomness in polyfactory? #460
-
I am attempting to use polyfactory to output a yaml template based on some deeply nested pydantic models. Right now, I am grappling with a behavior where some Optional fields are sometimes present in the output and other times completely missing. I would like values to be generated all the time for all fields. Is there a straightforward way to make this happen? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To answer the question in your title
To answer the question in your post
You can combine these and it would ensure you always get the same non optional values from dataclasses import dataclass
from polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str | None
class PersonFactory(DataclassFactory[Person]):
__model__ = Person
__random_seed__ = 1
__allow_none_optionals__ = False
person = PersonFactory.build()
print(person.name) |
Beta Was this translation helpful? Give feedback.
To answer the question in your title
__random_seed__
To answer the question in your post
__allow_none_optionals__
You can combine these and it would ensure you always get the same non optional values