Skip to content

Commit d37b074

Browse files
committed
fix(env): catch EnvCommandError instead of CalledProcessError when detecting active python
1 parent 770f07f commit d37b074

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
@@ -549,7 +549,7 @@ def _detect_active_python(self) -> str | None:
549549
self._io.write_error_line(
550550
f"Found: {executable}", verbosity=Verbosity.VERBOSE
551551
)
552-
except CalledProcessError:
552+
except EnvCommandError:
553553
self._io.write_error_line(
554554
"Unable to detect the current active python executable. Falling back to"
555555
" default.",

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)