You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deftest_schema1_empty():
withpytest.raises(MultipleInvalid) asexception_info:
Schema1({})
assertlen(exception_info.value.errors) ==2assertstr(exception_info.value.errors[0]) =="required key not provided @ data['value1']"assertstr(exception_info.value.errors[1]) =="required key not provided @ data['value2']"
The test fails 1 over 3-4 times.
I found it is related to the use of a set, that is unordered in python in schema_builder.py
Current code:
def_compile_mapping(self, schema, invalid_msg=None):
"""Create validator for given mapping."""invalid_msg=invalid_msgor'mapping value'# Keys that may be requiredall_required_keys=set(keyforkeyinschemaifkeyisnotExtraand ((self.requiredandnotisinstance(key, (Optional, Remove)))
orisinstance(key, Required)))
# Keys that may have defaultsall_default_keys=set(keyforkeyinschemaifisinstance(key, Required)
orisinstance(key, Optional))
My proposal (that works for me) would be to use a dict instead of a set (to preserve validations errors order):
def_compile_mapping(self, schema, invalid_msg=None):
"""Create validator for given mapping."""invalid_msg=invalid_msgor'mapping value'# Keys that may be requiredall_required_keys= {}
forkeyinschema:
ifkeyisnotExtra \
and ((self.required \
andnotisinstance(key, (Optional, Remove))) \
orisinstance(key, Required)):
all_required_keys[key] =key# Keys that may have defaultsall_default_keys= {}
forkeyinschema:
ifisinstance(key, Required) orisinstance(key, Optional):
all_default_keys[key] =key
The text was updated successfully, but these errors were encountered:
Just to confirm I correctly got your point. When you say "The test fails 1 over 3-4 times." you mean it fails every 3 to 4 times you run it, presumably because exception_info.value.errors[0] sometimes contains "required key not provided @ data['value1']" and sometimes ""required key not provided @ data['value2']"?
When validating this schema:
With this test:
The test fails 1 over 3-4 times.
I found it is related to the use of a set, that is unordered in python in schema_builder.py
Current code:
My proposal (that works for me) would be to use a dict instead of a set (to preserve validations errors order):
The text was updated successfully, but these errors were encountered: