diff --git a/src/snowflake/cli/api/project/definition_manager.py b/src/snowflake/cli/api/project/definition_manager.py index d0cae66812..663e581563 100644 --- a/src/snowflake/cli/api/project/definition_manager.py +++ b/src/snowflake/cli/api/project/definition_manager.py @@ -26,11 +26,10 @@ class DefinitionManager: _project_config_paths: List[Path] def __init__(self, project_arg: Optional[str] = None) -> None: - search_path = os.getcwd() - if project_arg: - search_path = os.path.abspath(project_arg) - project_root = DefinitionManager.find_project_root(Path(search_path)) - if not project_root: + project_root = Path( + os.path.abspath(project_arg) if project_arg else os.getcwd() + ) + if not self._base_definition_file_if_available(project_root): raise MissingConfiguration( f"Cannot find project definition (snowflake.yml). Please provide a path to the project or run this command in a valid project directory." ) diff --git a/tests/project/test_definition_manager.py b/tests/project/test_definition_manager.py index 385dec20d1..165b701ea0 100644 --- a/tests/project/test_definition_manager.py +++ b/tests/project/test_definition_manager.py @@ -2,6 +2,7 @@ from unittest import TestCase, mock from unittest.mock import patch +from snowflake.cli.api.exceptions import MissingConfiguration from snowflake.cli.api.project.definition_manager import DefinitionManager from tests.project.fixtures import * @@ -40,29 +41,22 @@ def test_finds_local_project_definition(self, mock_getcwd): @mock.patch("os.path.abspath", return_value="/hello/world/test") def test_double_dash_project_parameter_provided(self, mock_abs): with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file: - definition_manager = DefinitionManager("/hello/world/test") - assert definition_manager._project_config_paths == [ - Path("/hello/world/snowflake.yml") - ] + with pytest.raises(MissingConfiguration): + DefinitionManager("/hello/world/test") @mock.patch("os.path.abspath", return_value="/hello/world/test/again") def test_dash_p_parameter_provided(self, mock_abs): with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file: - definition_manager = DefinitionManager("/hello/world/test/again") - assert definition_manager._project_config_paths == [ - Path("/hello/world/snowflake.yml") - ] + with pytest.raises(MissingConfiguration): + DefinitionManager("/hello/world/test/again") @mock.patch("os.getcwd", return_value="/hello/world") @mock.patch("os.path.abspath", return_value="/hello/world/relative") def test_dash_p_with_relative_parameter_provided(self, mock_abs, mock_getcwd): with mock_is_file_for("/hello/world/snowflake.yml") as mock_is_file: mock_getcwd.return_value = "/hello/world" - definition_manager = DefinitionManager("./relative") - mock_abs.assert_called_with("./relative") - assert definition_manager._project_config_paths == [ - Path("/hello/world/snowflake.yml") - ] + with pytest.raises(MissingConfiguration): + DefinitionManager("./relative") @mock.patch("os.path.abspath", return_value="/tmp") def test_find_definition_files_reached_root(self, mock_abs):