diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 0af2a004719..7e8d118759c 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -86,7 +86,7 @@ def handle(self) -> int: self.line(self.poetry.package.pretty_version) else: self.line( - f"{self.poetry.package.name}" + f"{self.poetry.package.pretty_name}" f" {self.poetry.package.pretty_version}" ) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index 8d671273bbb..4772a400be1 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -10,7 +10,10 @@ if TYPE_CHECKING: from cleo.testers.command_tester import CommandTester + from poetry.poetry import Poetry from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter + from tests.types import ProjectFactory @pytest.fixture() @@ -23,6 +26,18 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: return command_tester_factory("version") +@pytest.fixture +def poetry_with_underscore( + project_factory: ProjectFactory, fixture_dir: FixtureDirGetter +) -> Poetry: + source = fixture_dir("simple_project") + pyproject_content = (source / "pyproject.toml").read_text(encoding="utf-8") + pyproject_content = pyproject_content.replace("simple-project", "simple_project") + return project_factory( + "project_with_underscore", pyproject_content=pyproject_content + ) + + @pytest.mark.parametrize( "version, rule, expected", [ @@ -79,6 +94,14 @@ def test_version_show(tester: CommandTester) -> None: assert tester.io.fetch_output() == "simple-project 1.2.3\n" +def test_version_show_with_underscore( + command_tester_factory: CommandTesterFactory, poetry_with_underscore: Poetry +) -> None: + tester = command_tester_factory("version", poetry=poetry_with_underscore) + tester.execute() + assert tester.io.fetch_output() == "simple_project 1.2.3\n" + + def test_short_version_show(tester: CommandTester) -> None: tester.execute("--short") assert tester.io.fetch_output() == "1.2.3\n"