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 @@ -626,7 +626,9 @@ def _load_plugins(self, io: IO) -> None:

self._disable_plugins = io.input.has_parameter_option("--no-plugins")

if not self._disable_plugins:
if not self._disable_plugins and not io.input.has_parameter_option(
["--version", "-V"], only_params=True
):
from poetry.plugins.application_plugin import ApplicationPlugin
from poetry.plugins.plugin_manager import PluginManager

Expand Down
19 changes: 19 additions & 0 deletions tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from cleo.testers.application_tester import ApplicationTester

from poetry.__version__ import __version__
from poetry.console.application import Application
from poetry.console.commands.command import Command
from poetry.plugins.application_plugin import ApplicationPlugin
Expand Down Expand Up @@ -83,6 +84,24 @@ def test_application_execute_plugin_command(with_add_command_plugin: None) -> No
assert tester.status_code == 0


@pytest.mark.parametrize("flag", ["--version", "-V"])
def test_application_with_plugins_skipped_for_version(
flag: str, with_add_command_plugin: None, mocker: MockerFixture
) -> None:
app = Application()

manager_mock = mocker.patch(
"poetry.plugins.plugin_manager.PluginManager", autospec=True
)

Comment on lines +87 to +96
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add an assertion that the version output is correct, not just that the exit code is 0

Since this test is meant to validate the version behavior, it should also assert the actual output, not just success and plugin behavior. Please add a check that tester.io.fetch_output() (or similar) includes the expected version string (e.g. __version__ or app.get_version()), so changes to the version output are caught by this test.

Suggested implementation:

@pytest.mark.parametrize("flag", ["--version", "-V"])
def test_application_with_plugins_skipped_for_version(
    flag: str, with_add_command_plugin: None, mocker: MockerFixture
) -> None:
    app = Application()

    manager_mock = mocker.patch(
        "poetry.plugins.plugin_manager.PluginManager", autospec=True
    )

    tester = ApplicationTester(app)
    tester.execute(flag)

    output = tester.io.fetch_output()

    assert tester.status_code == 0
    assert app._plugins_loaded is True
    manager_mock.assert_not_called()
    assert __version__ in output

To make this compile, ensure this test module imports __version__ from Poetry's version module near the top of the file, for example:

from poetry.__version__ import __version__

If a different version symbol or helper (e.g. Application().version or Application().get_version()) is already used elsewhere in the tests, adjust the assertion to check for that value instead of __version__.

tester = ApplicationTester(app)
tester.execute(flag)

assert tester.status_code == 0
assert __version__ in tester.io.fetch_output()
manager_mock.assert_not_called()


def test_application_execute_plugin_command_with_plugins_disabled(
with_add_command_plugin: None,
) -> None:
Expand Down
Loading