From 1c948e40536e2227a1525628d36aa6dd693a06b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Sun, 15 Sep 2024 12:19:22 -0300 Subject: [PATCH] Fail command install if cannot be installed (#9333) An error code is returned if the installation command fails. Also the style is changed from warning to error. Tests was updated. --- src/poetry/console/commands/install.py | 7 +++---- tests/console/commands/test_install.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index 63f4f93cb48..87479c33c03 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -200,11 +200,10 @@ def handle(self) -> int: " use --no-root.\n" "If you want to use Poetry only for dependency management" " but not for packaging, you can disable package mode by setting" - " package-mode = false in your pyproject.toml file.\n" - "In a future version of Poetry this warning will become an error!", - style="warning", + " package-mode = false in your pyproject.toml file.\n", + style="error", ) - return 0 + return 1 if overwrite: self.overwrite(log_install.format(tag="success")) diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 2692fa59f88..696bf493822 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -136,7 +136,7 @@ def test_group_options_are_passed_to_the_installer( status_code = tester.execute(options) - if options == "--no-root --only-root": + if options == "--no-root --only-root" or with_root: assert status_code == 1 return else: @@ -322,7 +322,7 @@ def test_invalid_groups_with_without_only( if not should_raise: tester.execute(cmd_args) - assert tester.status_code == 0 + assert tester.status_code == 1 else: with pytest.raises(GroupNotFound, match=r"^Group\(s\) not found:") as e: tester.execute(cmd_args) @@ -345,7 +345,7 @@ def test_remove_untracked_outputs_deprecation_warning( tester.execute("--remove-untracked") - assert tester.status_code == 0 + assert tester.status_code == 1 assert ( "The `--remove-untracked` option is deprecated, use the `--sync` option" " instead.\n" in tester.io.fetch_error() @@ -440,7 +440,11 @@ def test_install_warning_corrupt_root( tester = command_tester_factory("install", poetry=poetry) tester.execute("" if with_root else "--no-root") - assert tester.status_code == 0 + if error and with_root: + assert tester.status_code == 1 + else: + assert tester.status_code == 0 + if with_root and error: assert "The current project could not be installed: " in tester.io.fetch_error() else: