Skip to content

Commit ed4f442

Browse files
finswimmerradoering
authored andcommitted
fix(env): catch EnvCommandError instead of CalledProcessError when detecting active python
1 parent 570e8b5 commit ed4f442

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: src/poetry/utils/env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def _detect_active_python(self) -> str | None:
551551
self._io.write_error_line(
552552
f"Found: {executable}", verbosity=Verbosity.VERBOSE
553553
)
554-
except CalledProcessError:
554+
except EnvCommandError:
555555
self._io.write_error_line(
556556
(
557557
"Unable to detect the current active python executable. Falling"

Diff for: tests/utils/test_env.py

+12
Original file line numberDiff line numberDiff line change
@@ -1601,3 +1601,15 @@ def test_create_venv_project_name_empty_sets_correct_prompt(
16011601
},
16021602
prompt="virtualenv-py3.7",
16031603
)
1604+
1605+
1606+
def test_fallback_on_detect_active_python(poetry: Poetry, mocker: MockerFixture):
1607+
m = mocker.patch(
1608+
"subprocess.check_output",
1609+
side_effect=subprocess.CalledProcessError(1, "some command"),
1610+
)
1611+
env_manager = EnvManager(poetry)
1612+
active_python = env_manager._detect_active_python()
1613+
1614+
assert active_python is None
1615+
assert m.call_count == 1

0 commit comments

Comments
 (0)