MCPcopy
hub / github.com/pydantic/pydantic / test_serialize_extra_allow_subclass_1

Function test_serialize_extra_allow_subclass_1

tests/test_serialize.py:45–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43
44
45def test_serialize_extra_allow_subclass_1() -> None:
46 class Parent(BaseModel):
47 x: int
48
49 class Child(Parent):
50 model_config = ConfigDict(extra='allow')
51
52 class Model(BaseModel):
53 inner: Parent
54
55 m = Model(inner=Child(x=1, y=2))
56 assert m.inner.y == 2
57 assert m.model_dump() == {'inner': {'x': 1}}
58 assert json.loads(m.model_dump_json()) == {'inner': {'x': 1}}
59
60
61def test_serialize_extra_allow_subclass_2() -> None:

Callers

nothing calls this directly

Calls 4

model_dump_jsonMethod · 0.80
ModelClass · 0.70
ChildClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected