Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add pylint package and matchers #11

Merged
merged 2 commits into from
Aug 24, 2024
Merged

Conversation

MartinGotelli
Copy link
Owner

Add support for pydantic models:

poetry add pytest_matchers[pydantic]
pip install pytest_matchers[pydantic]
def test_pydantic():
    class Animal(BaseModel):  # pylint: disable=too-few-public-methods
        age: int
        name: str

    class Human(Animal):  # pylint: disable=too-few-public-methods
        money: float = 0

    class Dog(Animal):  # pylint: disable=too-few-public-methods
        breed: str = "Mongrel"

    messi = Human(age=33, name="Messi")
    lassie = Dog(age=3, name="Lassie", breed="Collie")
    tweety = Animal(age=1, name="Tweety")

    assert_match(messi, is_pydantic())
    assert_match(lassie, is_pydantic())
    assert_match(messi, is_pydantic(Human))
    assert_match(lassie, is_pydantic(Dog, age=3, name="Lassie", breed="Collie"))
    assert_match(tweety, is_pydantic(age=1))
    assert_match(messi, is_pydantic(Human, age=33, strict=False))

@MartinGotelli MartinGotelli merged commit 618e6ca into main Aug 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant