From 92b17e3a8978ace8e4505ebe3b1e1f712ffd4310 Mon Sep 17 00:00:00 2001 From: Sami Jawhar Date: Thu, 19 Nov 2020 18:16:12 -0600 Subject: [PATCH] Fix exp checkout queued and cleanup (#4914) --- dvc/repo/experiments/__init__.py | 5 ++++- tests/func/experiments/test_experiments.py | 24 +++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 009a2b998..e1447fb4f 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -847,7 +847,7 @@ class Experiments: self._scm_checkout(rev) branch = self._get_branch_containing(rev) - m = self.BRANCH_RE.match(branch) + m = self.BRANCH_RE.match(branch) if branch else None if m and m.group("checkpoint"): kwargs.update({"allow_missing": True, "quiet": True}) @@ -874,6 +874,9 @@ class Experiments: remove(tmp) if dirty: self._unstash_workspace() + args_file = os.path.join(self.repo.tmp_dir, self.PACKED_ARGS_FILE) + if os.path.exists(args_file): + remove(args_file) if need_checkout: dvc_checkout(self.repo, **kwargs) diff --git a/tests/func/experiments/test_experiments.py b/tests/func/experiments/test_experiments.py index 4bdd75246..732d4ea5a 100644 --- a/tests/func/experiments/test_experiments.py +++ b/tests/func/experiments/test_experiments.py @@ -111,20 +111,34 @@ def test_modify_params(tmp_dir, scm, dvc, mocker, changes, expected): ).read_text().strip() == expected -def test_checkout(tmp_dir, scm, dvc, exp_stage): - results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"]) +@pytest.mark.parametrize("queue", [True, False]) +def test_checkout(tmp_dir, scm, dvc, exp_stage, queue): + metrics_original = (tmp_dir / "metrics.yaml").read_text().strip() + results = dvc.experiments.run( + exp_stage.addressing, params=["foo=2"], queue=queue + ) exp_a = first(results) - results = dvc.experiments.run(exp_stage.addressing, params=["foo=3"]) + results = dvc.experiments.run( + exp_stage.addressing, params=["foo=3"], queue=queue + ) exp_b = first(results) dvc.experiments.checkout(exp_a) assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 2" - assert (tmp_dir / "metrics.yaml").read_text().strip() == "foo: 2" + assert ( + (tmp_dir / "metrics.yaml").read_text().strip() == metrics_original + if queue + else "foo: 2" + ) dvc.experiments.checkout(exp_b) assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 3" - assert (tmp_dir / "metrics.yaml").read_text().strip() == "foo: 3" + assert ( + (tmp_dir / "metrics.yaml").read_text().strip() == metrics_original + if queue + else "foo: 3" + ) def test_get_baseline(tmp_dir, scm, dvc, exp_stage):