| 376 | |
| 377 | |
| 378 | def test_field_min_items_deprecation(): |
| 379 | m = '`min_items` is deprecated and will be removed. use `min_length` instead' |
| 380 | with pytest.warns(PydanticDeprecatedSince20, match=m): |
| 381 | |
| 382 | class Model(BaseModel): |
| 383 | x: list[int] = Field(None, min_items=1) |
| 384 | |
| 385 | with pytest.raises(ValidationError) as exc_info: |
| 386 | Model(x=[]) |
| 387 | assert exc_info.value.errors(include_url=False) == [ |
| 388 | { |
| 389 | 'type': 'too_short', |
| 390 | 'loc': ('x',), |
| 391 | 'msg': 'List should have at least 1 item after validation, not 0', |
| 392 | 'input': [], |
| 393 | 'ctx': {'field_type': 'List', 'min_length': 1, 'actual_length': 0}, |
| 394 | } |
| 395 | ] |
| 396 | |
| 397 | |
| 398 | def test_field_min_items_with_min_length(): |