| 416 | |
| 417 | |
| 418 | def 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 | |
| 438 | def test_field_max_items_with_max_length(): |