()
| 131 | |
| 132 | |
| 133 | def test_private_attribute_annotation(): |
| 134 | class Model(BaseModel): |
| 135 | """The best model""" |
| 136 | |
| 137 | _foo: str |
| 138 | |
| 139 | assert Model.__private_attributes__ == {'_foo': PrivateAttr(PydanticUndefined)} |
| 140 | assert repr(Model.__doc__) == "'The best model'" |
| 141 | |
| 142 | m = Model() |
| 143 | with pytest.raises(AttributeError): |
| 144 | m._foo |
| 145 | |
| 146 | m._foo = '123' |
| 147 | assert m._foo == '123' |
| 148 | |
| 149 | m._foo = None |
| 150 | assert m._foo is None |
| 151 | |
| 152 | del m._foo |
| 153 | |
| 154 | with pytest.raises(AttributeError): |
| 155 | m._foo |
| 156 | |
| 157 | m._foo = '123' |
| 158 | assert m._foo == '123' |
| 159 | |
| 160 | assert m.model_dump() == {} |
| 161 | assert m.__dict__ == {} |
| 162 | |
| 163 | |
| 164 | def test_underscore_attrs_are_private(): |
nothing calls this directly
no test coverage detected