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: 2 additions & 2 deletions src/poetry_plugin_shell/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def handle(self) -> int:
# Setting this to avoid spawning unnecessary nested shells
os.environ["POETRY_ACTIVE"] = "1"
shell = Shell.get()
shell.activate(env)
exit_code = shell.activate(env)
os.environ.pop("POETRY_ACTIVE")

return 0
return exit_code or 0

def _is_venv_activated(self) -> bool:
return bool(os.environ.get("POETRY_ACTIVE")) or getattr(
Expand Down
17 changes: 14 additions & 3 deletions tests/test_shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("shell")


def test_shell(tester: CommandTester, mocker: MockerFixture) -> None:
shell_activate = mocker.patch("poetry_plugin_shell.shell.Shell.activate")
@pytest.mark.parametrize(
("shell_exit_code", "expected_status_code"),
[(None, 0), (0, 0), (3, 3)],
)
def test_shell(
tester: CommandTester,
mocker: MockerFixture,
shell_exit_code: int | None,
expected_status_code: int,
) -> None:
shell_activate = mocker.patch(
"poetry_plugin_shell.shell.Shell.activate", return_value=shell_exit_code
)

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
assert tester.status_code == expected_status_code


def test_shell_already_active(tester: CommandTester, mocker: MockerFixture) -> None:
Expand Down
Loading