diff --git a/cosmos/operators/local.py b/cosmos/operators/local.py index e6a09748f..caeee1c1c 100644 --- a/cosmos/operators/local.py +++ b/cosmos/operators/local.py @@ -298,6 +298,8 @@ def run_command( env.update(env_vars) flags = [ + "--project-dir", + str(tmp_project_dir), "--profiles-dir", str(profile_path.parent), "--profile", diff --git a/tests/operators/test_local.py b/tests/operators/test_local.py index c054cf4d1..6e1a6f6a9 100644 --- a/tests/operators/test_local.py +++ b/tests/operators/test_local.py @@ -703,18 +703,26 @@ def test_dbt_docs_gcs_local_operator(): @patch("cosmos.config.ProfileConfig.ensure_profile") @patch("cosmos.operators.local.DbtLocalBaseOperator.run_subprocess") @patch("cosmos.operators.local.DbtLocalBaseOperator.run_dbt_runner") +@patch("cosmos.operators.local.tempfile.TemporaryDirectory") @pytest.mark.parametrize("invocation_mode", [InvocationMode.SUBPROCESS, InvocationMode.DBT_RUNNER]) def test_operator_execute_deps_parameters( + mock_temporary_directory, mock_dbt_runner, mock_subprocess, mock_ensure_profile, mock_exception_handling, mock_store_compiled_sql, invocation_mode, + tmp_path, ): + project_dir = tmp_path / "mock_project_tmp_dir" + project_dir.mkdir() + expected_call_kwargs = [ "/usr/local/bin/dbt", "deps", + "--project-dir", + project_dir.as_posix(), "--profiles-dir", "/path/to", "--profile", @@ -732,6 +740,7 @@ def test_operator_execute_deps_parameters( invocation_mode=invocation_mode, ) mock_ensure_profile.return_value.__enter__.return_value = (Path("/path/to/profile"), {"ENV_VAR": "value"}) + mock_temporary_directory.return_value.__enter__.return_value = project_dir.as_posix() task.execute(context={"task_instance": MagicMock()}) if invocation_mode == InvocationMode.SUBPROCESS: assert mock_subprocess.call_args_list[0].kwargs["command"] == expected_call_kwargs