diff --git a/cosmos/operators/virtualenv.py b/cosmos/operators/virtualenv.py index babc431b8..5036064f2 100644 --- a/cosmos/operators/virtualenv.py +++ b/cosmos/operators/virtualenv.py @@ -125,7 +125,7 @@ def _get_or_create_venv_py_interpreter(self) -> str: ) self.log.info(f"Checking if {str(self.__lock_file)} exists") - while not self.__is_lock_available(): + while not self._is_lock_available(): self.log.info("Waiting for lock to release") time.sleep(1) @@ -154,7 +154,7 @@ def _pid(self) -> int: return os.getpid() @depends_on_virtualenv_dir - def __is_lock_available(self) -> bool: + def _is_lock_available(self) -> bool: if self.__lock_file.is_file(): with open(self.__lock_file, "r") as lf: pid = int(lf.read()) diff --git a/tests/operators/test_virtualenv.py b/tests/operators/test_virtualenv.py index e13228f57..3997fa75e 100644 --- a/tests/operators/test_virtualenv.py +++ b/tests/operators/test_virtualenv.py @@ -72,15 +72,18 @@ def test_run_command( @patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.store_compiled_sql") @patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.exception_handling") @patch("cosmos.operators.virtualenv.DbtLocalBaseOperator.subprocess_hook") +@patch("cosmos.operators.virtualenv.DbtVirtualenvBaseOperator._is_lock_available") @patch("airflow.hooks.base.BaseHook.get_connection") def test_supply_virtualenv_dir_flag( mock_get_connection, + mock_lock_available, mock_subprocess_hook, mock_exception_handling, mock_store_compiled_sql, mock_calculate_openlineage_events_completes, mock_execute, ): + mock_lock_available.return_value = True mock_get_connection.return_value = Connection( conn_id="fake_conn", conn_type="postgres", diff --git a/tests/test_converter.py b/tests/test_converter.py index 23423b912..3b409256f 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -114,12 +114,14 @@ def test_converter_creates_dag_with_project_path_str(mock_load_dbt_graph, execut # (ExecutionMode.DOCKER, {"image": "sample-image"}), ], ) +@patch("cosmos.converter.DbtGraph.filtered_nodes", nodes) +@patch("cosmos.converter.DbtGraph.load") def test_converter_raises_warning(mock_load_dbt_graph, execution_mode, virtualenv_dir, operator_args, caplog): """ This test will raise a warning if we are trying to pass ExecutionMode != `VirtualEnv` and still pass a defined `virtualenv_dir` """ - project_config = ProjectConfig(dbt_project_path=SAMPLE_DBT_PROJECT) + project_config = ProjectConfig(dbt_project_path=SAMPLE_DBT_PROJECT.as_posix()) execution_config = ExecutionConfig(execution_mode=execution_mode, virtualenv_dir=virtualenv_dir) render_config = RenderConfig(emit_datasets=True) profile_config = ProfileConfig( @@ -137,8 +139,6 @@ def test_converter_raises_warning(mock_load_dbt_graph, execution_mode, virtualen operator_args=operator_args, ) - assert converter - assert "`ExecutionConfig.virtualenv_dir` is only supported when \ ExecutionConfig.execution_mode is set to ExecutionMode.VIRTUALENV." in caplog.text