MCPcopy
hub / github.com/pydantic/pydantic / test_private_attribute

Function test_private_attribute

tests/test_private_attributes.py:12–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10
11
12def test_private_attribute():
13 default = {'a': {}}
14
15 class Model(BaseModel):
16 _foo = PrivateAttr(default)
17
18 assert set(Model.__private_attributes__) == {'_foo'}
19
20 m = Model()
21 assert m._foo == default
22 assert m._foo is not default
23 assert m._foo['a'] is not default['a']
24
25 m._foo = None
26 assert m._foo is None
27
28 assert m.model_dump() == {}
29 assert m.__dict__ == {}
30
31
32def test_private_attribute_double_leading_underscore():

Callers

nothing calls this directly

Calls 2

ModelClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected