()
| 215 | |
| 216 | |
| 217 | def test_slots_are_ignored(): |
| 218 | class Model(BaseModel): |
| 219 | __slots__ = ( |
| 220 | 'foo', |
| 221 | '_bar', |
| 222 | ) |
| 223 | |
| 224 | def __init__(self): |
| 225 | super().__init__() |
| 226 | for attr_ in self.__slots__: |
| 227 | object.__setattr__(self, attr_, 'spam') |
| 228 | |
| 229 | assert Model.__private_attributes__ == {} |
| 230 | assert set(Model.__slots__) == {'foo', '_bar'} |
| 231 | m1 = Model() |
| 232 | m2 = Model() |
| 233 | |
| 234 | for attr in Model.__slots__: |
| 235 | assert object.__getattribute__(m1, attr) == 'spam' |
| 236 | |
| 237 | # In v2, you are always allowed to set instance attributes if the name starts with `_`. |
| 238 | m1._bar = 'not spam' |
| 239 | assert m1._bar == 'not spam' |
| 240 | assert m2._bar == 'spam' |
| 241 | |
| 242 | with pytest.raises(ValueError, match='"Model" object has no field "foo"'): |
| 243 | m1.foo = 'not spam' |
| 244 | |
| 245 | |
| 246 | def test_default_and_default_factory_used_error(): |
nothing calls this directly
no test coverage detected