I have below class and need to write a unit test for it using pytest I guess
from pydantic import BaseModel, Field
class cl1(BaseModel):
a1 :str = Field(None,title="blablabla")
a2 :str = Field(None,title="blabla2")
a3 :int = Field(title="bbbb1", default=0)
a4 :int = Field(title="bbbb2", default=10000)
I tried this way but it failed with TypeError: can only concatenate str not ("NoneType") to str
import pytest
from mymodule import cl1
def test_cl1_defaults():
obj = cl1()
assert obj.a1 is None
assert obj.a2 is None
assert obj.a3 == 0
assert obj.a4 == 10000
I expect the code of test that will work
New contributor
Yevgeniya Perepechenko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.