| 491 | |
| 492 | |
| 493 | def test_allow_mutation(): |
| 494 | m = '`allow_mutation` is deprecated and will be removed. use `frozen` instead' |
| 495 | with pytest.warns(PydanticDeprecatedSince20, match=m): |
| 496 | |
| 497 | class Model(BaseModel): |
| 498 | model_config = ConfigDict(validate_assignment=True) |
| 499 | x: int = Field(allow_mutation=False) |
| 500 | y: int = Field(allow_mutation=True) |
| 501 | |
| 502 | m = Model(x=1, y=2) |
| 503 | |
| 504 | assert m.x == 1 |
| 505 | with pytest.raises(ValidationError) as exc_info: |
| 506 | m.x = 2 |
| 507 | assert exc_info.value.errors(include_url=False) == [ |
| 508 | {'input': 2, 'loc': ('x',), 'msg': 'Field is frozen', 'type': 'frozen_field'} |
| 509 | ] |
| 510 | |
| 511 | m.y = 3 |
| 512 | assert m.y == 3 |
| 513 | |
| 514 | |
| 515 | def test_field_regex(): |