stage: allow duplicate values in _read_env (#6007)

This commit is contained in:
Peter Rowlands (변기호)
2021-05-14 15:49:41 +02:00
committed by GitHub
parent c6f49bd23d
commit 71ea12877d
2 changed files with 25 additions and 2 deletions
+5 -2
View File
@@ -296,8 +296,11 @@ class Stage(params.StageParams):
for out in self.outs:
current = self._read_env(out, checkpoint_func=checkpoint_func)
if set(env.keys()).intersection(set(current.keys())):
raise DvcException("Duplicated env variable")
if any(
env.get(key) != current.get(key)
for key in set(env.keys()).intersection(current.keys())
):
raise DvcException("Conflicting values for env variable")
env.update(current)
return env
+20
View File
@@ -122,3 +122,23 @@ def test_external_outs(tmp_path_factory, dvc):
create_stage(Stage, dvc, "path.dvc", outs=["remote://myremote/foo"])
create_stage(Stage, dvc, "path.dvc", outs=[os.fspath(foo)], external=True)
def test_env(dvc):
from dvc.env import DVC_ROOT
from dvc.exceptions import DvcException
from dvc.stage import create_stage
stage = create_stage(Stage, dvc, "path.dvc", outs=["foo", "bar"])
with mock.patch.object(stage, "_read_env", return_value={"foo": "foo"}):
env = stage.env()
assert env == {DVC_ROOT: dvc.root_dir, "foo": "foo"}
def mock_read_env(out, **kwargs):
return {"foo": str(out)}
with pytest.raises(DvcException) as exc:
with mock.patch.object(stage, "_read_env", mock_read_env):
env = stage.env()
assert exc.value == "Conflicting values for env variable"