Skip to content

Commit f74276d

Browse files
committed
adding test
1 parent 198471b commit f74276d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/serializers/test_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,10 @@ def test_no_warn_on_exclude() -> None:
11041104

11051105

11061106
def test_warn_on_missing_field() -> None:
1107+
class AModel(BasicModel): ...
1108+
1109+
class BModel(BasicModel): ...
1110+
11071111
s = SchemaSerializer(
11081112
core_schema.model_schema(
11091113
BasicModel,
@@ -1113,7 +1117,7 @@ def test_warn_on_missing_field() -> None:
11131117
core_schema.tagged_union_schema(
11141118
choices={
11151119
'a': core_schema.model_schema(
1116-
BasicModel,
1120+
AModel,
11171121
core_schema.model_fields_schema(
11181122
{
11191123
'type': core_schema.model_field(core_schema.literal_schema(['a'])),
@@ -1122,7 +1126,7 @@ def test_warn_on_missing_field() -> None:
11221126
),
11231127
),
11241128
'b': core_schema.model_schema(
1125-
BasicModel,
1129+
BModel,
11261130
core_schema.model_fields_schema(
11271131
{
11281132
'type': core_schema.model_field(core_schema.literal_schema(['b'])),
@@ -1139,9 +1143,9 @@ def test_warn_on_missing_field() -> None:
11391143
)
11401144
)
11411145

1142-
value = BasicModel(root=BasicModel(type='a', a=1))
1146+
value = BasicModel(root=AModel(type='a')) # missing 'a' field
11431147
with pytest.warns(
11441148
UserWarning,
1145-
match='Expected 2 fields but got 1 for field root of type `BasicModel` with value.+',
1149+
match='Expected 2 fields but got 1 for field root of type.+',
11461150
):
11471151
assert s.to_python(value) == {'root': {'type': 'a'}}

0 commit comments

Comments
 (0)