From ed5441f5659bd66b56ce475504be98031907621c Mon Sep 17 00:00:00 2001 From: finswimmer Date: Mon, 19 Dec 2022 13:29:52 +0100 Subject: [PATCH] fix(env): catch EnvCommandError instead of CalledProcessError when detecting active python --- src/poetry/utils/env.py | 2 +- tests/utils/test_env.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 6c4ccef0a6c..408d0c0f232 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -551,7 +551,7 @@ def _detect_active_python(self) -> str | None: self._io.write_error_line( f"Found: {executable}", verbosity=Verbosity.VERBOSE ) - except CalledProcessError: + except EnvCommandError: self._io.write_error_line( ( "Unable to detect the current active python executable. Falling" diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 1b65c8a052e..23cbbda3e7f 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1601,3 +1601,15 @@ def test_create_venv_project_name_empty_sets_correct_prompt( }, prompt="virtualenv-py3.7", ) + + +def test_fallback_on_detect_active_python(poetry: Poetry, mocker: MockerFixture): + m = mocker.patch( + "subprocess.check_output", + side_effect=subprocess.CalledProcessError(1, "some command"), + ) + env_manager = EnvManager(poetry) + active_python = env_manager._detect_active_python() + + assert active_python is None + assert m.call_count == 1