From 7c52f6573653d4bc227ec64927dde56b28c4185f Mon Sep 17 00:00:00 2001 From: pawel Date: Sat, 20 Jul 2019 08:54:37 +0200 Subject: [PATCH] metric: show: xpath should override xpath set after run --- dvc/repo/metrics/show.py | 2 +- tests/func/test_metrics.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index 758ba3a47..f82beb5b3 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -190,7 +190,7 @@ def _collect_metrics(repo, path, recursive, typ, xpath, branch): if not typ and isinstance(o.metric, dict): t = o.metric.get(o.PARAM_METRIC_TYPE, typ) - x = o.metric.get(o.PARAM_METRIC_XPATH, xpath) + x = xpath or o.metric.get(o.PARAM_METRIC_XPATH) else: t = typ x = xpath diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 3e2286c88..4159c6461 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -831,3 +831,16 @@ class TestShouldDisplayMetricsEvenIfMetricIsMissing(object): in caplog.text ) assert 0 == ret + + +def test_show_xpath_should_override_stage_xpath(dvc_repo): + metric_file = "metric" + metric = {"m1": 0.1, "m2": 0.2} + with open(metric_file, "w") as fobj: + json.dump(metric, fobj) + + dvc_repo.run(cmd="", overwrite=True, metrics=[metric_file]) + dvc_repo.metrics.modify(metric_file, typ="json", xpath="m2") + + result = dvc_repo.metrics.show(xpath="m1") + assert result == {"": {metric_file: [0.1]}}