parametrize_from_file
parametrize_from_file copied to clipboard
Converting input parameters to Pydantic base models
Hello! I am using your library to parametrize my tests! I am using Pydantic in my project and would like to use it to (de)serialize the input objects with it. My test case looks as follows:
test_object:
- person:
first_name: "John"
last_name: "Doe"
len: 4
class Person(BaseModel):
first_name: str
last_name: str
@pff.parametrize(schema=[pff.cast(person=Person)])
def test_object(person: Person, len: int):
assert person.first_name == "John"
assert len(person.first_name) == len
I don't know if I am using the schema
and the cast
correctly in this context, but I would like to convert the complex object into a base model. Alternatively, I can do this:
class Person(BaseModel):
first_name: str
last_name: str
@pff.parametrize
def test_object(person: dict, len: int):
person_obj = Person(**person)
assert person_obj.first_name == "John"
assert len(person_obj.first_name) == len
which works, but it would be nice if the library could do the conversion on its own! Is there a way of doing this?