From 641e9b8cf898928b4e4257e1e5cda243fc1f1aa7 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 23 Aug 2021 11:51:25 +0100 Subject: Slightly nicer error message for not. --- jsonschema/_validators.py | 5 ++--- jsonschema/tests/test_validators.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index 7f05505..e4cfa35 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -397,9 +397,8 @@ def oneOf(validator, oneOf, instance, schema): def not_(validator, not_schema, instance, schema): if validator.is_valid(instance, not_schema): - yield ValidationError( - f"{not_schema!r} is not allowed for {instance!r}", - ) + message = f"{instance!r} should not be valid under {not_schema!r}" + yield ValidationError(message) def if_(validator, if_schema, instance, schema): diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 36d41d3..7f5f387 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -1022,7 +1022,7 @@ class TestValidationErrorDetails(TestCase): self.assertEqual(error.validator, "not") self.assertEqual( error.message, - "{'const': 'foo'} is not allowed for 'foo'", + "'foo' should not be valid under {'const': 'foo'}", ) self.assertEqual(error.path, deque([])) self.assertEqual(error.json_path, "$") -- cgit v1.2.1