MCPcopy
hub / github.com/pydantic/pydantic / test_recursive

Function test_recursive

tests/test_json.py:354–369  ·  view source on GitHub ↗
(create_module)

Source from the content-addressed store, hash-verified

352
353
354def test_recursive(create_module):
355 module = create_module(
356 # language=Python
357 """
358from __future__ import annotations
359from typing import Optional
360from pydantic import BaseModel
361
362class Model(BaseModel):
363 value: int
364 nested: Optional[Model] = None
365"""
366 )
367 M = module.Model
368
369 assert M(value=1, nested=M(value=2)).model_dump_json(exclude_none=True) == '{"value":1,"nested":{"value":2}}'
370
371
372def test_resolve_ref_schema_recursive_model():

Callers

nothing calls this directly

Calls 3

create_moduleFunction · 0.85
model_dump_jsonMethod · 0.80
MClass · 0.70

Tested by

no test coverage detected