Skip to content

Commit

Permalink
fix(env): catch EnvCommandError instead of CalledProcessError when de…
Browse files Browse the repository at this point in the history
…tecting active python
  • Loading branch information
finswimmer authored and radoering committed Jan 21, 2023
1 parent 570e8b5 commit ed4f442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed4f442

Please sign in to comment.