| 59 | |
| 60 | |
| 61 | def test_experiment_exists(tmp_dir, scm, dvc, exp_stage, mocker, workspace): |
| 62 | dvc.experiments.run( |
| 63 | exp_stage.addressing, |
| 64 | name="foo", |
| 65 | params=["foo=2"], |
| 66 | tmp_dir=not workspace, |
| 67 | ) |
| 68 | |
| 69 | new_mock = mocker.spy(BaseStashQueue, "_stash_exp") |
| 70 | with pytest.raises(ExperimentExistsError): |
| 71 | dvc.experiments.run( |
| 72 | exp_stage.addressing, |
| 73 | name="foo", |
| 74 | params=["foo=3"], |
| 75 | tmp_dir=not workspace, |
| 76 | ) |
| 77 | new_mock.assert_not_called() |
| 78 | |
| 79 | results = dvc.experiments.run( |
| 80 | exp_stage.addressing, |
| 81 | name="foo", |
| 82 | params=["foo=3"], |
| 83 | force=True, |
| 84 | tmp_dir=not workspace, |
| 85 | ) |
| 86 | exp = first(results) |
| 87 | |
| 88 | fs = scm.get_fs(exp) |
| 89 | with fs.open("metrics.yaml", mode="r", encoding="utf-8") as fobj: |
| 90 | assert fobj.read().strip() == "foo: 3" |
| 91 | |
| 92 | |
| 93 | @pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.") |