diff --git a/dvc/repo/experiments/exceptions.py b/dvc/repo/experiments/exceptions.py index 383bb603a..d83d4a000 100644 --- a/dvc/repo/experiments/exceptions.py +++ b/dvc/repo/experiments/exceptions.py @@ -66,18 +66,6 @@ class MultipleBranchError(DvcException): self.ref_infos = ref_infos -class ApplyConflictError(InvalidArgumentError): - def __init__(self, name): - super().__init__( - f"Experiment '{name}' cannot be applied to because your current " - "workspace contains changes which would be overwritten. Either " - "'git stash' your current changes before applying this " - "experiment, or re-run this command with '--force' to overwrite " - "your current changes." - ) - self.name = name - - class AmbiguousExpRefInfo(InvalidArgumentError): def __init__( self, diff --git a/tests/func/experiments/test_experiments.py b/tests/func/experiments/test_experiments.py index 0e742854b..3996ae315 100644 --- a/tests/func/experiments/test_experiments.py +++ b/tests/func/experiments/test_experiments.py @@ -110,15 +110,13 @@ def test_failed_exp_workspace( def test_apply(tmp_dir, scm, dvc, exp_stage): from dvc.exceptions import InvalidArgumentError - from dvc.repo.experiments.exceptions import ApplyConflictError results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"], tmp_dir=True) exp_a = first(results) - results = dvc.experiments.run( + dvc.experiments.run( exp_stage.addressing, params=["foo=3"], tmp_dir=True, name="foo" ) - exp_b = first(results) with pytest.raises(InvalidArgumentError): dvc.experiments.apply("bar") @@ -127,12 +125,6 @@ def test_apply(tmp_dir, scm, dvc, exp_stage): assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 2" assert (tmp_dir / "metrics.yaml").read_text().strip() == "foo: 2" - with pytest.raises(ApplyConflictError): - dvc.experiments.apply(exp_b, force=False) - # failed apply should revert everything to prior state - assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 2" - assert (tmp_dir / "metrics.yaml").read_text().strip() == "foo: 2" - dvc.experiments.apply("foo") assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 3" assert (tmp_dir / "metrics.yaml").read_text().strip() == "foo: 3" @@ -168,8 +160,6 @@ def test_apply_failed(tmp_dir, scm, dvc, failed_exp_stage, test_queue): def test_apply_queued(tmp_dir, scm, dvc, exp_stage): - from dvc.repo.experiments.exceptions import ApplyConflictError - metrics_original = (tmp_dir / "metrics.yaml").read_text().strip() dvc.experiments.run( exp_stage.addressing, params=["foo=2"], name="exp-a", queue=True @@ -186,29 +176,18 @@ def test_apply_queued(tmp_dir, scm, dvc, exp_stage): assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 2" assert (tmp_dir / "metrics.yaml").read_text().strip() == metrics_original - with pytest.raises(ApplyConflictError): - dvc.experiments.apply(queue_revs["exp-b"], force=False) - dvc.experiments.apply(queue_revs["exp-b"]) assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 3" assert (tmp_dir / "metrics.yaml").read_text().strip() == metrics_original def test_apply_untracked(tmp_dir, scm, dvc, exp_stage): - from dvc.repo.experiments.exceptions import ApplyConflictError - results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"]) exp = first(results) tmp_dir.gen("untracked", "untracked") tmp_dir.gen("params.yaml", "conflict") - with pytest.raises(ApplyConflictError): - dvc.experiments.apply(exp, force=False) - - assert (tmp_dir / "untracked").read_text() == "untracked" - assert (tmp_dir / "params.yaml").read_text() == "conflict" - - dvc.experiments.apply(exp, force=True) + dvc.experiments.apply(exp) assert (tmp_dir / "untracked").read_text() == "untracked" assert (tmp_dir / "params.yaml").read_text().strip() == "foo: 2"