MCPcopy
hub / github.com/pydantic/pydantic / test_recursive_model

Function test_recursive_model

tests/test_forward_ref.py:685–701  ·  view source on GitHub ↗
(create_module)

Source from the content-addressed store, hash-verified

683
684
685def test_recursive_model(create_module):
686 module = create_module(
687 # language=Python
688 """
689from __future__ import annotations
690from typing import Optional
691from pydantic import BaseModel
692
693class Foobar(BaseModel):
694 x: int
695 y: Optional[Foobar] = None
696"""
697 )
698 f = module.Foobar(x=1, y={'x': 2})
699 assert f.model_dump() == {'x': 1, 'y': {'x': 2, 'y': None}}
700 assert f.model_fields_set == {'x', 'y'}
701 assert f.y.model_fields_set == {'x'}
702
703
704@pytest.mark.skipif(sys.version_info < (3, 10), reason='needs 3.10 or newer')

Callers

nothing calls this directly

Calls 2

create_moduleFunction · 0.85
model_dumpMethod · 0.45

Tested by

no test coverage detected