(create_module)
| 683 | |
| 684 | |
| 685 | def test_recursive_model(create_module): |
| 686 | module = create_module( |
| 687 | # language=Python |
| 688 | """ |
| 689 | from __future__ import annotations |
| 690 | from typing import Optional |
| 691 | from pydantic import BaseModel |
| 692 | |
| 693 | class 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') |
nothing calls this directly
no test coverage detected