Skip to content

Commit 21c0c90

Browse files
authored
Fix error caused by a bad base_python path (#3122)
1 parent 381e37a commit 21c0c90

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/changelog/3105.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle ``FileNotFoundError`` when the ``base_python`` interpreter doesn't exist

src/tox/tox_env/python/virtual_env/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: ARG
132132
# the base pythons are injected into the virtualenv_env_vars, so we don't need to use it here
133133
try:
134134
interpreter = self.creator.interpreter
135-
except RuntimeError: # if can't find
135+
except (FileNotFoundError, RuntimeError): # Unable to find the interpreter
136136
return None
137137
return PythonInfo(
138138
implementation=interpreter.implementation,

tests/tox_env/python/test_python_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,10 @@ def test_list_installed_deps_explicit_cli(
277277
assert "pip==" in result.out
278278
else:
279279
assert "pip==" not in result.out
280+
281+
282+
def test_usedevelop_with_nonexistent_basepython(tox_project: ToxProjectCreator) -> None:
283+
ini = "[testenv]\nusedevelop = true\n[testenv:unused]\nbasepython = /nonexistent/bin/python"
284+
project = tox_project({"tox.ini": ini})
285+
result = project.run()
286+
assert result.code == 0

0 commit comments

Comments
 (0)