diff --git a/dvc/stage/run.py b/dvc/stage/run.py index 332c7c8dc1..1182cd1341 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -47,7 +47,7 @@ def warn_if_fish(executable): def _enforce_cmd_list(cmd): assert cmd - return cmd if isinstance(cmd, list) else [cmd] + return cmd if isinstance(cmd, list) else cmd.splitlines() def prepare_kwargs(stage, checkpoint_func=None): diff --git a/tests/func/test_repro_multistage.py b/tests/func/test_repro_multistage.py index d7c8ec5725..98c73ac138 100644 --- a/tests/func/test_repro_multistage.py +++ b/tests/func/test_repro_multistage.py @@ -529,7 +529,14 @@ def test_repro_multiple_params(tmp_dir, dvc): assert dvc.reproduce(stage.addressing) == [stage] -def test_repro_list_of_commands_in_order(tmp_dir, dvc): +@pytest.mark.parametrize("multiline", [True, False]) +def test_repro_list_of_commands_in_order(tmp_dir, dvc, multiline): + cmd = ["echo foo>foo", "echo bar>bar"] + if multiline: + cmd = "\n".join(cmd) + + dump_yaml("dvc.yaml", {"stages": {"multi": {"cmd": cmd}}}) + (tmp_dir / "dvc.yaml").write_text( dedent( """\ @@ -546,19 +553,16 @@ def test_repro_list_of_commands_in_order(tmp_dir, dvc): assert (tmp_dir / "bar").read_text() == "bar\n" -def test_repro_list_of_commands_raise_and_stops_after_failure(tmp_dir, dvc): - (tmp_dir / "dvc.yaml").write_text( - dedent( - """\ - stages: - multi: - cmd: - - echo foo>foo - - failed_command - - echo baz>bar - """ - ) - ) +@pytest.mark.parametrize("multiline", [True, False]) +def test_repro_list_of_commands_raise_and_stops_after_failure( + tmp_dir, dvc, multiline +): + cmd = ["echo foo>foo", "failed_command", "echo baz>bar"] + if multiline: + cmd = "\n".join(cmd) + + dump_yaml("dvc.yaml", {"stages": {"multi": {"cmd": cmd}}}) + with pytest.raises(ReproductionError): dvc.reproduce(targets=["multi"]) assert (tmp_dir / "foo").read_text() == "foo\n"