diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index d6d41383cf6..fd72a30a312 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -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) if not self._disable_plugins: from poetry.plugins.application_plugin import ApplicationPlugin diff --git a/tests/console/test_application.py b/tests/console/test_application.py index 2fc8546bb3c..f0e380e482e 100644 --- a/tests/console/test_application.py +++ b/tests/console/test_application.py @@ -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 @@ -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()