From fbc3dfc48b0e1b6f0d5d7a5b80126a04b2aabe76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:43:22 +0200 Subject: [PATCH] self install: in this context the project is not a package so we should set package-mode to false --- .../console/commands/self/self_command.py | 1 + tests/console/commands/self/test_install.py | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/console/commands/self/test_install.py diff --git a/src/poetry/console/commands/self/self_command.py b/src/poetry/console/commands/self/self_command.py index db626f1ed4e..6b049d3b459 100644 --- a/src/poetry/console/commands/self/self_command.py +++ b/src/poetry/console/commands/self/self_command.py @@ -73,6 +73,7 @@ def generate_system_pyproject(self) -> None: package.python_versions = ".".join(str(v) for v in self.env.version_info[:3]) content = Factory.create_pyproject_from_package(package=package) + content["tool"]["poetry"]["package-mode"] = False # type: ignore[index] for key in preserved: content["tool"]["poetry"][key] = preserved[key] # type: ignore[index] diff --git a/tests/console/commands/self/test_install.py b/tests/console/commands/self/test_install.py new file mode 100644 index 00000000000..3490a2e7bdd --- /dev/null +++ b/tests/console/commands/self/test_install.py @@ -0,0 +1,62 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from poetry.console.commands.self.install import SelfInstallCommand + + +if TYPE_CHECKING: + from cleo.testers.command_tester import CommandTester + + from tests.types import CommandTesterFactory + + +@pytest.fixture +def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: + return command_tester_factory("self install") + + +@pytest.mark.parametrize( + "pyproject_content", + ( + None, + """\ +[tool.poetry] +name = "poetry-instance" +version = "1.2" +description = "" +authors = [] +license = "" +# no package-mode -> defaults to true + +[tool.poetry.dependencies] +python = "3.9" +poetry = "1.2" +""", + ), +) +def test_self_install( + tester: CommandTester, + pyproject_content: str | None, +) -> None: + command = tester.command + assert isinstance(command, SelfInstallCommand) + pyproject_path = command.system_pyproject + if pyproject_content: + pyproject_path.write_text(pyproject_content) + else: + assert not pyproject_path.exists() + + tester.execute() + + expected_output = """\ +Updating dependencies +Resolving dependencies... + +Writing lock file +""" + + assert tester.io.fetch_output() == expected_output + assert tester.io.fetch_error() == ""