MCPcopy
hub / github.com/pydantic/pydantic / test_field_min_items_deprecation

Function test_field_min_items_deprecation

tests/test_deprecated.py:378–395  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

376
377
378def 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
398def test_field_min_items_with_min_length():

Callers

nothing calls this directly

Calls 2

ModelClass · 0.70
errorsMethod · 0.45

Tested by

no test coverage detected