From 0138b948aef6bb624ce62d70c630f1dae776f8b3 Mon Sep 17 00:00:00 2001 From: Marton Vago Date: Thu, 20 Nov 2025 11:05:56 +0000 Subject: [PATCH 1/2] fix: :bug: sort and deduplicate issues before raising error --- src/check_datapackage/check.py | 3 ++- tests/test_check.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/check_datapackage/check.py b/src/check_datapackage/check.py index 2d3a8c6c..49db8600 100644 --- a/src/check_datapackage/check.py +++ b/src/check_datapackage/check.py @@ -89,11 +89,12 @@ class for more details, especially about the default values. issues = _check_object_against_json_schema(properties, schema) issues += apply_extensions(properties, config.extensions) issues = exclude(issues, config.exclusions, properties) + issues = sorted(set(issues)) if error and issues: raise DataPackageError(issues) - return sorted(set(issues)) + return issues def _set_should_fields_to_required(schema: dict[str, Any]) -> dict[str, Any]: diff --git a/tests/test_check.py b/tests/test_check.py index aaee4e68..020cb15e 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -10,7 +10,7 @@ example_resource_properties, ) from check_datapackage.exclusion import Exclusion -from check_datapackage.extensions import Extensions +from check_datapackage.extensions import Extensions, RequiredCheck from check_datapackage.internals import _map from tests.test_extensions import lowercase_check @@ -630,9 +630,16 @@ def test_fail_primary_key_with_bad_array_item(): def test_error_as_true(): - properties = { - "name": 123, - } + resources_required = RequiredCheck( + jsonpath="$.resources", + message="'resources' is a required property", + ) + + with raises(DataPackageError) as error: + check( + {}, + error=True, + config=Config(extensions=Extensions(required_checks=[resources_required])), + ) - with raises(DataPackageError): - check(properties, error=True) + assert str(error).count(resources_required.message) == 1 From 1cc7c55d84250a21041447904d35cae1cbadf412 Mon Sep 17 00:00:00 2001 From: Marton Vago Date: Thu, 20 Nov 2025 15:37:16 +0000 Subject: [PATCH 2/2] revert: :rewind: revert separate test for error --- tests/test_check.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_check.py b/tests/test_check.py index 020cb15e..1038d91e 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -630,6 +630,15 @@ def test_fail_primary_key_with_bad_array_item(): def test_error_as_true(): + properties = { + "name": 123, + } + + with raises(DataPackageError): + check(properties, error=True) + + +def test_error_true_no_duplicate_issues(): resources_required = RequiredCheck( jsonpath="$.resources", message="'resources' is a required property",