diff --git a/src/poetry_plugin_shell/command.py b/src/poetry_plugin_shell/command.py index 234ac85..5058bc1 100644 --- a/src/poetry_plugin_shell/command.py +++ b/src/poetry_plugin_shell/command.py @@ -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( diff --git a/tests/test_shell_command.py b/tests/test_shell_command.py index 8b05732..366f365 100644 --- a/tests/test_shell_command.py +++ b/tests/test_shell_command.py @@ -22,8 +22,19 @@ 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) @@ -31,7 +42,7 @@ def test_shell(tester: CommandTester, mocker: MockerFixture) -> None: 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: