MCPcopy
hub / github.com/pydantic/pydantic / test_default_factory_field

Function test_default_factory_field

tests/test_main.py:155–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153
154
155def test_default_factory_field():
156 def myfunc():
157 return 1
158
159 class Model(BaseModel):
160 a: int = Field(default_factory=myfunc)
161
162 m = Model()
163 assert str(m) == 'a=1'
164 assert repr(Model.model_fields['a']) == 'FieldInfo(annotation=int, required=False, default_factory=myfunc)'
165 assert dict(m) == {'a': 1}
166 assert m.model_dump_json() == '{"a":1}'
167
168
169def test_comparing(UltraSimpleModel):

Callers

nothing calls this directly

Calls 2

model_dump_jsonMethod · 0.80
ModelClass · 0.70

Tested by

no test coverage detected