From 7b0a3b4cc2b254d96618de6ca28acd5b9537f2ed Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 16 Jan 2025 14:48:30 +0200 Subject: [PATCH] ensure metadata is valid for result before assigning --- .github/workflows/build-test.yml | 6 +++--- example/__init__.py | 0 example/{example.py => test_example.py} | 0 pytest_opentmi/OpenTmiReport.py | 11 +++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 example/__init__.py rename example/{example.py => test_example.py} (100%) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 25480c6..1665379 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python @@ -54,13 +54,13 @@ jobs: htmlcov/* junit/* - name: install rel deps - if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' + if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' run: | pip install wheel twine python setup.py sdist python setup.py bdist_wheel - name: upload to pypi - if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' + if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' env: TWINE_USERNAME: "${{secrets.TWINE_USERNAME}}" TWINE_PASSWORD: "${{secrets.TWINE_PASSWORD}}" diff --git a/example/__init__.py b/example/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/example/example.py b/example/test_example.py similarity index 100% rename from example/example.py rename to example/test_example.py diff --git a/pytest_opentmi/OpenTmiReport.py b/pytest_opentmi/OpenTmiReport.py index 6339ce8..47b540a 100644 --- a/pytest_opentmi/OpenTmiReport.py +++ b/pytest_opentmi/OpenTmiReport.py @@ -1,6 +1,7 @@ """ OpenTmiReport module """ +import json import os import time import datetime @@ -215,6 +216,16 @@ def _new_result(self, report): for item in self.config.option.metadata: key, value = item + if not isinstance(key, str): + logger.warning(f"Metadata key is not string: {key}") + continue + # ensure value is JSON serializable with JSON.dumps + try: + json.dumps(value) + except TypeError: + logger.warning(f"Metadata value is not JSON serializable: {value}") + continue + # Dut if key.startswith('DUT') and not dut: dut = Dut()