From 1cdc464e58a7735d34f982c8e58d2cd0ea03038f Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Mon, 26 Aug 2024 17:08:57 +0200 Subject: [PATCH] Issue #7 switch to `--track-metrics-json` to prepare for other outputs (s3) --- .github/workflows/benchmarks.yaml | 2 +- qa/tools/apex_algorithm_qa_tools/__init__.py | 2 +- .../pytest_track_metrics.py | 14 ++++++++------ qa/unittests/tests/test_pytest_track_metrics.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml index e5bcf8b..349fa81 100644 --- a/.github/workflows/benchmarks.yaml +++ b/.github/workflows/benchmarks.yaml @@ -28,7 +28,7 @@ jobs: --log-cli-level=INFO \ --random-subset=1 \ --html report/report.html --self-contained-html \ - --track-metrics-report=report/metrics.json \ + --track-metrics-json=report/metrics.json \ --basetemp=tmp_path_root \ --upload-assets-run-id="gh-$GITHUB_RUN_ID" \ --upload-assets-endpoint-url="https://s3.waw3-1.cloudferro.com" \ diff --git a/qa/tools/apex_algorithm_qa_tools/__init__.py b/qa/tools/apex_algorithm_qa_tools/__init__.py index f7492b7..d4ff0c2 100644 --- a/qa/tools/apex_algorithm_qa_tools/__init__.py +++ b/qa/tools/apex_algorithm_qa_tools/__init__.py @@ -1,4 +1,4 @@ # TODO #15 Flatten apex_algorithm_qa_tools to a single module and push as much functionality to https://github.com/ESA-APEx/esa-apex-toolbox-python -__version__ = "0.0.1" +__version__ = "0.1.1" diff --git a/qa/tools/apex_algorithm_qa_tools/pytest_track_metrics.py b/qa/tools/apex_algorithm_qa_tools/pytest_track_metrics.py index f7ba99f..c23a290 100644 --- a/qa/tools/apex_algorithm_qa_tools/pytest_track_metrics.py +++ b/qa/tools/apex_algorithm_qa_tools/pytest_track_metrics.py @@ -20,7 +20,7 @@ def test_dummy(track_metric): track_metric("x squared", x*x) ... -- Run the tests with `--track-metrics-report=path/to/metrics.json` +- Run the tests with `--track-metrics-json=path/to/metrics.json` to store metrics in a JSON file """ @@ -36,7 +36,7 @@ def test_dummy(track_metric): def pytest_addoption(parser: pytest.Parser): parser.addoption( - "--track-metrics-report", + "--track-metrics-json", metavar="PATH", help="Path to JSON file to store test/benchmark metrics.", ) @@ -59,7 +59,7 @@ class TrackMetricsReporter: def __init__( self, path: Union[str, Path], user_properties_key: str = "track_metrics" ): - self.path = Path(path) + self._json_path = Path(path) self.metrics: List[dict] = [] self.user_properties_key = user_properties_key @@ -79,14 +79,16 @@ def pytest_runtest_logreport(self, report: pytest.TestReport): ) def pytest_sessionfinish(self, session): - with self.path.open("w", encoding="utf8") as f: + with self._json_path.open("w", encoding="utf8") as f: json.dump(self.metrics, f, indent=2) def pytest_report_header(self): - return f"Plugin `track_metrics` is active, reporting to {self.path}" + return f"Plugin `track_metrics` is active, reporting to {self._json_path}" def pytest_terminal_summary(self, terminalreporter): - terminalreporter.write_sep("-", f"Generated track_metrics report: {self.path}") + terminalreporter.write_sep( + "-", f"Generated track_metrics report: {self._json_path}" + ) def get_metrics( self, user_properties: List[Tuple[str, Any]] diff --git a/qa/unittests/tests/test_pytest_track_metrics.py b/qa/unittests/tests/test_pytest_track_metrics.py index c1af9a3..dbedad7 100644 --- a/qa/unittests/tests/test_pytest_track_metrics.py +++ b/qa/unittests/tests/test_pytest_track_metrics.py @@ -26,7 +26,7 @@ def test_3plus(track_metric, x): metrics_path = tmp_path / "metrics.json" run_result = pytester.runpytest( - f"--track-metrics-report={metrics_path}", + f"--track-metrics-json={metrics_path}", ) run_result.stdout.re_match_lines( [r"Plugin `track_metrics` is active, reporting to"]