Skip to content

Converting input parameters to Pydantic base models #23

@raminqaf

Description

@raminqaf

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions