Last active
November 20, 2020 13:39
-
-
Save gidgid/ab4b825b968c32eef5af73d1292696f9 to your computer and use it in GitHub Desktop.
Pydantic models set method doesnt execute type coercion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from pydantic import BaseModel, ValidationError | |
| class Pizza(BaseModel): | |
| toppings_count: int | |
| size: str | |
| def test_field_set_doesnt_perform_conversion_either(): | |
| pizza = Pizza(toppings_count='4', size='XL') # 1 | |
| assert pizza.toppings_count == 4 | |
| pizza.toppings_count = 'no conversion' # 2 | |
| assert pizza.toppings_count == 'no conversion' # 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment