MCPcopy
hub / github.com/pydantic/pydantic / test_allow_mutation

Function test_allow_mutation

tests/test_deprecated.py:493–512  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

491
492
493def 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
515def test_field_regex():

Callers

nothing calls this directly

Calls 2

ModelClass · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected