Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ def _load_plugins(self, io: IO) -> None:
if self._plugins_loaded:
return

self._disable_plugins = io.input.has_parameter_option("--no-plugins")
self._disable_plugins = io.input.has_parameter_option(
"--no-plugins"
) or io.input.has_parameter_option(["--version", "-V"], only_params=True)
Comment thread
pratyushsinghal7 marked this conversation as resolved.

if not self._disable_plugins:
from poetry.plugins.application_plugin import ApplicationPlugin
Expand Down
26 changes: 26 additions & 0 deletions tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from poetry.console.application import Application
from poetry.console.commands.command import Command
from poetry.plugins.application_plugin import ApplicationPlugin
from poetry.plugins.plugin_manager import PluginManager
from poetry.plugins.plugin_manager import ProjectPluginCache
from poetry.repositories.cached_repository import CachedRepository
from poetry.utils.authenticator import Authenticator
Expand Down Expand Up @@ -73,6 +74,31 @@ def test_application_with_plugins_disabled(with_add_command_plugin: None) -> Non
assert tester.status_code == 0


@pytest.mark.parametrize("version_option", ["--version", "-V"])
def test_application_version_does_not_load_plugins(
version_option: str, mocker: MockerFixture
) -> None:
load_plugins = mocker.spy(PluginManager, "load_plugins")
tester = ApplicationTester(Application())

tester.execute(version_option)

load_plugins.assert_not_called()
assert tester.status_code == 0


@pytest.mark.parametrize("command", ["run python -V", "run -- python -V"])
def test_application_subcommand_version_loads_plugins(
command: str, mocker: MockerFixture
) -> None:
load_plugins = mocker.spy(PluginManager, "load_plugins")
tester = ApplicationTester(Application())

tester.execute(command)

load_plugins.assert_called_once()


def test_application_execute_plugin_command(with_add_command_plugin: None) -> None:
app = Application()

Expand Down