Skip to content

Commit 9e1062a

Browse files
authored
Show Python path for Poetry in debug info (#10588)
1 parent bbd2be8 commit 9e1062a

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/poetry/console/commands/debug/info.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import sys
44

5+
from pathlib import Path
6+
57
from poetry.console.commands.command import Command
68

79

@@ -17,8 +19,10 @@ def handle(self) -> int:
1719
self.line(
1820
"\n".join(
1921
[
20-
f"<info>Version</info>: <comment>{self.poetry.VERSION}</>",
21-
f"<info>Python</info>: <comment>{poetry_python_version}</>",
22+
f"<info>Version</info>: <comment>{self.poetry.VERSION}</>",
23+
f"<info>Python</info>: <comment>{poetry_python_version}</>",
24+
f"<info>Path</info>: <comment>{Path(sys.prefix)}</>",
25+
f"<info>Executable</info>: <comment>{Path(sys.executable) if sys.executable else 'Unknown'}</>",
2226
]
2327
)
2428
)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
from pathlib import Path
6+
from typing import TYPE_CHECKING
7+
8+
import pytest
9+
10+
from poetry.__version__ import __version__
11+
from poetry.utils.env import MockEnv
12+
13+
14+
if TYPE_CHECKING:
15+
from cleo.testers.command_tester import CommandTester
16+
from pytest_mock import MockerFixture
17+
18+
from tests.types import CommandTesterFactory
19+
20+
21+
@pytest.fixture(autouse=True)
22+
def setup(mocker: MockerFixture) -> None:
23+
mocker.patch(
24+
"poetry.utils.env.EnvManager.get",
25+
return_value=MockEnv(
26+
path=Path("/prefix"), base=Path("/base/prefix"), is_venv=True
27+
),
28+
)
29+
mocker.patch(
30+
"sys.prefix",
31+
"/poetry/prefix",
32+
)
33+
mocker.patch(
34+
"sys.executable",
35+
"/poetry/prefix/bin/python",
36+
)
37+
38+
39+
@pytest.fixture
40+
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
41+
return command_tester_factory("debug info")
42+
43+
44+
def test_debug_info_displays_complete_info(tester: CommandTester) -> None:
45+
tester.execute()
46+
47+
expected = f"""
48+
Poetry
49+
Version: {__version__}
50+
Python: {".".join(str(v) for v in sys.version_info[:3])}
51+
Path: {Path("/poetry/prefix")}
52+
Executable: {Path("/poetry/prefix/bin/python")}
53+
54+
Virtualenv
55+
Python: 3.7.0
56+
Implementation: CPython
57+
Path: {Path("/prefix")}
58+
Executable: {Path(sys.executable)}
59+
Valid: True
60+
61+
Base
62+
Platform: darwin
63+
OS: posix
64+
Python: {".".join(str(v) for v in sys.version_info[:3])}
65+
Path: {Path("/base/prefix")}
66+
Executable: python
67+
"""
68+
69+
assert tester.io.fetch_output() == expected

0 commit comments

Comments
 (0)