Skip to content

Instantly share code, notes, and snippets.

@gidgid
Last active November 20, 2020 13:39
Show Gist options
  • Save gidgid/ab4b825b968c32eef5af73d1292696f9 to your computer and use it in GitHub Desktop.
Save gidgid/ab4b825b968c32eef5af73d1292696f9 to your computer and use it in GitHub Desktop.
Pydantic models set method doesnt execute type coercion
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