diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index bd0d5d772..cabf5a0d4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -101,9 +101,9 @@ jobs: cache-dependency-path: "**/pyproject.toml" - name: Collect schema files from aas-specs run: | - mkdir -p ./test/adapter/schema - curl -sSLf -o ./test/adapter/schema/aasJSONSchema.json https://raw.githubusercontent.com/admin-shell-io/aas-specs-metamodel/refs/tags/${{ env.X_AAS_SPECS_RELEASE_TAG }}/schemas/json/aas.json - curl -sSLf -o ./test/adapter/schema/aasXMLSchema.xsd https://raw.githubusercontent.com/admin-shell-io/aas-specs-metamodel/refs/tags/${{ env.X_AAS_SPECS_RELEASE_TAG }}/schemas/xml/AAS.xsd + mkdir -p ./test/adapter/schemas + curl -sSLf -o ./test/adapter/schemas/aasJSONSchema.json https://raw.githubusercontent.com/admin-shell-io/aas-specs-metamodel/refs/tags/${{ env.X_AAS_SPECS_RELEASE_TAG }}/schemas/json/aas.json + curl -sSLf -o ./test/adapter/schemas/aasXMLSchema.xsd https://raw.githubusercontent.com/admin-shell-io/aas-specs-metamodel/refs/tags/${{ env.X_AAS_SPECS_RELEASE_TAG }}/schemas/xml/AAS.xsd - name: Install Python dependencies run: | python -m pip install --upgrade pip @@ -112,6 +112,9 @@ jobs: run: | python test/_helper/setup_testdb.py -u "admin" -p "$COUCHDB_ADMIN_PASSWORD" - name: Test with coverage + unittest + env: + # Fail instead of silently skipping if the schema files above are missing (see test_helpers.py). + REQUIRE_SCHEMA_TESTS: "1" run: | python -m coverage run --source=basyx -m unittest - name: Report test coverage diff --git a/sdk/test/_helper/test_helpers.py b/sdk/test/_helper/test_helpers.py index 3633519a1..71975d4d8 100644 --- a/sdk/test/_helper/test_helpers.py +++ b/sdk/test/_helper/test_helpers.py @@ -7,6 +7,7 @@ import base64 import configparser +import os import os.path import urllib.error import urllib.request @@ -20,6 +21,12 @@ ) +# By default, the schema validation tests are skipped when the AAS schema files are missing, so that a plain local +# `python -m unittest` run doesn't require downloading them first. Set this environment variable to "1"/"true" +# (e.g. in CI) to instead make those tests fail if the files are missing, so a broken download can't silently cause +# the tests to be skipped without anyone noticing. +REQUIRE_SCHEMAS = os.environ.get("REQUIRE_SCHEMA_TESTS", "false").lower() in {"1", "true", "yes"} + # Check if CouchDB database is available. Otherwise, skip tests. try: request = urllib.request.Request( diff --git a/sdk/test/adapter/json/test_json_serialization.py b/sdk/test/adapter/json/test_json_serialization.py index e53cf6041..c727ba267 100644 --- a/sdk/test/adapter/json/test_json_serialization.py +++ b/sdk/test/adapter/json/test_json_serialization.py @@ -25,6 +25,8 @@ ) from jsonschema import validate # type: ignore +from test._helper.test_helpers import REQUIRE_SCHEMAS + JSON_SCHEMA_FILE = os.path.join( os.path.dirname(__file__), "../schemas/aasJSONSchema.json" ) @@ -72,6 +74,10 @@ class JsonSerializationSchemaTest(unittest.TestCase): @classmethod def setUpClass(cls): if not os.path.exists(JSON_SCHEMA_FILE): + if REQUIRE_SCHEMAS: + raise RuntimeError( + f"REQUIRE_SCHEMA_TESTS is set, but the JSON Schema does not exist at {JSON_SCHEMA_FILE}" + ) raise unittest.SkipTest( f"JSON Schema does not exist at {JSON_SCHEMA_FILE}, skipping test" ) diff --git a/sdk/test/adapter/xml/test_xml_serialization.py b/sdk/test/adapter/xml/test_xml_serialization.py index 625cd9943..0b5616743 100644 --- a/sdk/test/adapter/xml/test_xml_serialization.py +++ b/sdk/test/adapter/xml/test_xml_serialization.py @@ -18,6 +18,8 @@ ) from lxml import etree +from test._helper.test_helpers import REQUIRE_SCHEMAS + XML_SCHEMA_FILE = os.path.join(os.path.dirname(__file__), "../schemas/aasXMLSchema.xsd") @@ -63,6 +65,10 @@ class XMLSerializationSchemaTest(unittest.TestCase): @classmethod def setUpClass(cls): if not os.path.exists(XML_SCHEMA_FILE): + if REQUIRE_SCHEMAS: + raise RuntimeError( + f"REQUIRE_SCHEMA_TESTS is set, but the XSD schema does not exist at {XML_SCHEMA_FILE}" + ) raise unittest.SkipTest( f"XSD schema does not exist at {XML_SCHEMA_FILE}, skipping test" )