MCPcopy
hub / github.com/pydantic/pydantic / test_field_max_items

Function test_field_max_items

tests/test_deprecated.py:418–435  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

416
417
418def test_field_max_items():
419 m = '`max_items` is deprecated and will be removed. use `max_length` instead'
420 with pytest.warns(PydanticDeprecatedSince20, match=m):
421
422 class Model(BaseModel):
423 x: list[int] = Field(None, max_items=1)
424
425 with pytest.raises(ValidationError) as exc_info:
426 Model(x=[1, 2])
427 assert exc_info.value.errors(include_url=False) == [
428 {
429 'type': 'too_long',
430 'loc': ('x',),
431 'msg': 'List should have at most 1 item after validation, not 2',
432 'input': [1, 2],
433 'ctx': {'field_type': 'List', 'max_length': 1, 'actual_length': 2},
434 }
435 ]
436
437
438def test_field_max_items_with_max_length():

Callers

nothing calls this directly

Calls 2

ModelClass · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected