From eef74176cfbef780b39ad00bc8b10f10a019f00d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 5 May 2022 13:43:21 +0100 Subject: [PATCH] Ensure proper sorting of list in error message Fixes problem where error message was con consistent between runs. --- jsonschema/_utils.py | 2 +- jsonschema/tests/test_validators.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 7b48f07ac..a4ab2ad9d 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -113,7 +113,7 @@ def extras_msg(extras): verb = "was" else: verb = "were" - return ", ".join(repr(extra) for extra in extras), verb + return ", ".join(repr(extra) for extra in sorted(extras)), verb def ensure_list(thing): diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 0785f617e..23655a163 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -594,7 +594,7 @@ def test_unevaluated_items(self): message = self.message_for(instance=["foo", "bar"], schema=schema) self.assertIn( message, - "Unevaluated items are not allowed ('foo', 'bar' were unexpected)", + "Unevaluated items are not allowed ('bar', 'foo' were unexpected)", ) def test_unevaluated_properties(self): @@ -609,7 +609,7 @@ def test_unevaluated_properties(self): self.assertEqual( message, "Unevaluated properties are not allowed " - "('foo', 'bar' were unexpected)", + "('bar', 'foo' were unexpected)", )