| 338 | @parametrize |
| 339 | @pytest.mark.asyncio |
| 340 | async def test_pydantic_default_field(use_async: bool) -> None: |
| 341 | # should be excluded when defaults are used |
| 342 | model = ModelWithDefaultField.construct() |
| 343 | assert model.with_none_default is None |
| 344 | assert model.with_str_default == "foo" |
| 345 | assert cast(Any, await transform(model, Any, use_async)) == {} |
| 346 | |
| 347 | # should be included when the default value is explicitly given |
| 348 | model = ModelWithDefaultField.construct(with_none_default=None, with_str_default="foo") |
| 349 | assert model.with_none_default is None |
| 350 | assert model.with_str_default == "foo" |
| 351 | assert cast(Any, await transform(model, Any, use_async)) == {"with_none_default": None, "with_str_default": "foo"} |
| 352 | |
| 353 | # should be included when a non-default value is explicitly given |
| 354 | model = ModelWithDefaultField.construct(with_none_default="bar", with_str_default="baz") |
| 355 | assert model.with_none_default == "bar" |
| 356 | assert model.with_str_default == "baz" |
| 357 | assert cast(Any, await transform(model, Any, use_async)) == {"with_none_default": "bar", "with_str_default": "baz"} |
| 358 | |
| 359 | |
| 360 | class TypedDictIterableUnion(TypedDict): |