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
3 changes: 3 additions & 0 deletions src/poetry_plugin_shell/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ShellCommand(EnvCommand):
def handle(self) -> int:
from poetry_plugin_shell.shell import Shell

if os.environ.get("POETRY_ACTIVE") == "1" and not os.environ.get("VIRTUAL_ENV"):
os.environ.pop("POETRY_ACTIVE")

# Check if it's already activated or doesn't exist and won't be created
if self._is_venv_activated():
self.line(
Expand Down
19 changes: 19 additions & 0 deletions tests/test_shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def test_shell(tester: CommandTester, mocker: MockerFixture) -> None:


def test_shell_already_active(tester: CommandTester, mocker: MockerFixture) -> None:
assert isinstance(tester.command, ShellCommand)
os.environ["POETRY_ACTIVE"] = "1"
os.environ["VIRTUAL_ENV"] = str(tester.command.env.path)
shell_activate = mocker.patch("poetry_plugin_shell.shell.Shell.activate")

tester.execute()
Expand All @@ -50,6 +52,23 @@ def test_shell_already_active(tester: CommandTester, mocker: MockerFixture) -> N
assert tester.status_code == 0


def test_shell_stale_poetry_active(
tester: CommandTester, mocker: MockerFixture
) -> None:
assert isinstance(tester.command, ShellCommand)
os.environ["POETRY_ACTIVE"] = "1"
shell_activate = mocker.patch("poetry_plugin_shell.shell.Shell.activate")

tester.execute()

assert isinstance(tester.command, ShellCommand)
expected_output = f"Spawning shell within {tester.command.env.path}\n"

shell_activate.assert_called_once_with(tester.command.env)
assert tester.io.fetch_output() == expected_output
assert tester.status_code == 0


@pytest.mark.parametrize(
("poetry_active", "real_prefix", "prefix", "expected"),
[
Expand Down
Loading