First Steps
Once you have installed the package, you can start generating test data using object mothers.
Your First Object Mother
The object-mother-sindri package provides a set of built-in object mothers that you
can use to generate realistic test data. To create your first object mother, follow these steps:
- First import the object mother classes you want to use from the
object_mothermodule. - Then use the
any()method of the object mother to generate a random primitive value - Finally, you can use the generated values in your tests.
from object_mother import IntegerPrimitivesMother, StringPrimitivesMother
def test_user_creation() -> None:
user_request = {
"age": IntegerPrimitivesMother.any(),
"name": StringPrimitivesMother.any()
}
...
More about Object Mothers
Object mothers has a lot more to offer too. You can learn more about the object mother pattern, the built-in object mothers that are implemented, what methods they provide, and how to extend or create your custom object mothers in the Object Mothers section.