diff --git a/conformity/fields/structures.py b/conformity/fields/structures.py index ace52fc..c8ef07c 100644 --- a/conformity/fields/structures.py +++ b/conformity/fields/structures.py @@ -301,12 +301,12 @@ def errors(self, value): # type: (AnyType) -> ListType[Error] # Check for extra keys extra_keys = set(value.keys()) - set(self.contents.keys()) if extra_keys and not self.allow_extra_keys: - result.append( - Error( - 'Extra keys present: {}'.format(', '.join(six.text_type(key) for key in sorted(extra_keys))), + for extra_key in sorted(extra_keys): + result.append(Error( + 'Extra key present: {}'.format(six.text_type(extra_key)), code=ERROR_CODE_UNKNOWN, - ), - ) + pointer=six.text_type(extra_key), + )) if not result and self.additional_validator: return self.additional_validator.errors(value) diff --git a/tests/test_fields.py b/tests/test_fields.py index 234fab2..229c7ab 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -139,7 +139,8 @@ def test_complex(self): # type: () -> None sorted([ Error('Not an integer', pointer='child_ids.2'), Error('Missing key: address', code=ERROR_CODE_MISSING, pointer='address'), - Error('Extra keys present: another_bad, unsolicited_item', code=ERROR_CODE_UNKNOWN), + Error('Extra key present: another_bad', code=ERROR_CODE_UNKNOWN, pointer='another_bad'), + Error('Extra key present: unsolicited_item', code=ERROR_CODE_UNKNOWN, pointer='unsolicited_item'), Error('Not a set or frozenset', pointer='unique_things'), ]), ) diff --git a/tests/test_settings.py b/tests/test_settings.py index f1a0020..498c399 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -368,7 +368,7 @@ def test_validation(self): }, }) - assert '- inner_qux: Extra keys present: not_defined' in error_context.value.args[0] + assert '- inner_qux.not_defined: Extra key present: not_defined' in error_context.value.args[0] with pytest.raises(Settings.ImproperlyConfigured) as error_context: SettingsTwo({