Skip to content

Commit

Permalink
Issue #7 switch to --track-metrics-json to prepare for other output…
Browse files Browse the repository at this point in the history
…s (s3)
  • Loading branch information
soxofaan committed Aug 26, 2024
1 parent 59b56a6 commit 1cdc464
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion qa/tools/apex_algorithm_qa_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 8 additions & 6 deletions qa/tools/apex_algorithm_qa_tools/pytest_track_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand All @@ -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.",
)
Expand All @@ -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

Expand All @@ -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]]
Expand Down
2 changes: 1 addition & 1 deletion qa/unittests/tests/test_pytest_track_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 1cdc464

Please sign in to comment.