Skip to content

Commit 7b33040

Browse files
committed
better test
1 parent 9186014 commit 7b33040

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tests/validators/test_definitions_recursive.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,22 @@ class Model:
885885
),
886886
ref='model',
887887
)
888-
v = SchemaValidator(schema)
888+
v = SchemaValidator(schema, config=core_schema.CoreConfig(revalidate_instances='always'))
889889

890+
data = [Model(x=[Model(x=[])])]
890891
instance = Model(x=[])
891-
v.validate_assignment(instance, 'x', [Model(x=[])])
892-
assert instance.x == [Model(x=[])]
892+
v.validate_assignment(instance, 'x', data)
893+
assert instance.x == data
894+
895+
with pytest.raises(ValidationError) as exc_info:
896+
v.validate_assignment(instance, 'x', [Model(x=[Model(x=[Model(x=[123])])])])
897+
898+
assert exc_info.value.errors() == [
899+
{
900+
'type': 'dataclass_type',
901+
'loc': ('x', 0, 'x', 0, 'x', 0, 'x', 0),
902+
'msg': 'Input should be a dictionary or an instance of Model',
903+
'input': 123,
904+
'ctx': {'dataclass_name': 'Model'},
905+
}
906+
]

0 commit comments

Comments
 (0)