Skip to content

Commit

Permalink
Fail command install if cannot be installed (#9333)
Browse files Browse the repository at this point in the history
An error code is returned if the installation command fails. Also the
style is changed from warning to error.

Tests was updated.
  • Loading branch information
eamanu authored Sep 15, 2024
1 parent 119a3d7 commit 1c948e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,10 @@ def handle(self) -> int:
" use <c1>--no-root</c1>.\n"
"If you want to use Poetry only for dependency management"
" but not for packaging, you can disable package mode by setting"
" <c1>package-mode = false</> in your pyproject.toml file.\n"
"In a future version of Poetry this warning will become an error!",
style="warning",
" <c1>package-mode = false</> in your pyproject.toml file.\n",
style="error",
)
return 0
return 1

if overwrite:
self.overwrite(log_install.format(tag="success"))
Expand Down
12 changes: 8 additions & 4 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1c948e4

Please sign in to comment.