Skip to content

Instantly share code, notes, and snippets.

@gidgid
Created October 4, 2020 14:16
Show Gist options
  • Save gidgid/b4ee87310daee9ae16dc36a0537206c5 to your computer and use it in GitHub Desktop.
Save gidgid/b4ee87310daee9ae16dc36a0537206c5 to your computer and use it in GitHub Desktop.
Models that are not made of key-value pairs
import pytest
from typing import List
from pydantic import BaseModel
class Names(BaseModel):
values: List[str]
def test_values_is_not_part_of_the_input_data():
with pytest.raises(TypeError): # 1
Names(['name1', 'name2', 'name3']) # 1
class Name(BaseModel):
value: str
def test_name_isnt_a_primitive_string():
with pytest.raises(TypeError): # 2
Name('42 is the answer') # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment