| 318 | |
| 319 | |
| 320 | def test_fields(): |
| 321 | class Model(BaseModel): |
| 322 | x: int |
| 323 | y: int = 2 |
| 324 | |
| 325 | @computed_field |
| 326 | @property |
| 327 | def area(self) -> int: |
| 328 | return self.x * self.y |
| 329 | |
| 330 | m = Model(x=1) |
| 331 | assert len(Model.model_fields) == 2 |
| 332 | |
| 333 | with pytest.warns(PydanticDeprecatedSince211, match="Accessing the 'model_fields' attribute"): |
| 334 | assert len(m.model_fields) == 2 |
| 335 | |
| 336 | with pytest.warns(PydanticDeprecatedSince211, match="Accessing the 'model_computed_fields' attribute"): |
| 337 | assert len(m.model_computed_fields) == 1 |
| 338 | |
| 339 | match = '^The `__fields__` attribute is deprecated, use the `model_fields` class property instead.' |
| 340 | with pytest.warns(PydanticDeprecatedSince20, match=match): |
| 341 | assert len(Model.__fields__) == 2 |
| 342 | with pytest.warns(PydanticDeprecatedSince20, match=match): |
| 343 | assert len(m.__fields__) == 2 |
| 344 | |
| 345 | |
| 346 | def test_fields_set(): |