Skip to content

Commit b516801

Browse files
deronnaxradoering
andauthored
outputs 'env activate' verbose message on stderr (#10353)
Co-authored-by: Randy Döring <[email protected]>
1 parent 8e5426d commit b516801

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/poetry/console/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def configure_env(self, event: Event, event_name: str, _: EventDispatcher) -> No
581581
env = env_manager.create_venv()
582582

583583
if env.is_venv() and io.is_verbose():
584-
io.write_line(f"Using virtualenv: <comment>{env.path}</>")
584+
io.write_error_line(f"Using virtualenv: <comment>{env.path}</>")
585585

586586
command.set_env(env)
587587

tests/console/commands/env/test_activate.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import pytest
66

77
from poetry.utils._compat import WINDOWS
8+
from poetry.utils.env import MockEnv
89

910

1011
if TYPE_CHECKING:
12+
from cleo.testers.application_tester import ApplicationTester
1113
from cleo.testers.command_tester import CommandTester
1214
from pytest_mock import MockerFixture
1315

@@ -45,9 +47,8 @@ def test_env_activate_prints_correct_script(
4547

4648
tester.execute()
4749

48-
line = tester.io.fetch_output().split("\n")[0]
49-
assert line.startswith(command)
50-
assert line.endswith(f"activate{ext}")
50+
line = tester.io.fetch_output().rstrip("\n")
51+
assert line == f"{command} {tmp_venv.bin_dir}/activate{ext}"
5152

5253

5354
@pytest.mark.parametrize(
@@ -73,5 +74,22 @@ def test_env_activate_prints_correct_script_on_windows(
7374

7475
tester.execute()
7576

76-
line = tester.io.fetch_output().split("\n")[0]
77+
line = tester.io.fetch_output().rstrip("\n")
7778
assert line == f'{prefix}"{tmp_venv.bin_dir / ext!s}"'
79+
80+
81+
@pytest.mark.parametrize("verbosity", ["", "-v", "-vv", "-vvv"])
82+
def test_no_additional_output_in_verbose_mode(
83+
tmp_venv: VirtualEnv,
84+
mocker: MockerFixture,
85+
app_tester: ApplicationTester,
86+
verbosity: str,
87+
) -> None:
88+
mocker.patch("shellingham.detect_shell", return_value=("pwsh", None))
89+
mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv(is_venv=True))
90+
91+
# use an AppTester instead of a CommandTester to catch additional output
92+
app_tester.execute(f"env activate {verbosity}")
93+
94+
lines = app_tester.io.fetch_output().splitlines()
95+
assert len(lines) == 1

tests/console/commands/test_run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def test_run_passes_args_after_run_before_command_name_conflict(
9191
path.rename(path.parent / "run")
9292

9393
app_tester.execute(f"{args} python -V", decorated=True)
94-
assert app_tester.io.fetch_error() == ""
94+
assert (
95+
app_tester.io.remove_format(app_tester.io.fetch_error())
96+
== f"Using virtualenv: {env.path}\n"
97+
)
9598
assert env.executed == [["python", "-V"]]
9699

97100

0 commit comments

Comments
 (0)