From 21c0c90fbf1ec8651099abca22a2a27dc8b3dea1 Mon Sep 17 00:00:00 2001 From: Teejay Date: Fri, 8 Sep 2023 15:44:23 -0700 Subject: [PATCH] Fix error caused by a bad `base_python` path (#3122) --- docs/changelog/3105.bugfix.rst | 1 + src/tox/tox_env/python/virtual_env/api.py | 2 +- tests/tox_env/python/test_python_api.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/3105.bugfix.rst diff --git a/docs/changelog/3105.bugfix.rst b/docs/changelog/3105.bugfix.rst new file mode 100644 index 000000000..dd87507cd --- /dev/null +++ b/docs/changelog/3105.bugfix.rst @@ -0,0 +1 @@ +Handle ``FileNotFoundError`` when the ``base_python`` interpreter doesn't exist diff --git a/src/tox/tox_env/python/virtual_env/api.py b/src/tox/tox_env/python/virtual_env/api.py index 706f7ea44..c1c507247 100644 --- a/src/tox/tox_env/python/virtual_env/api.py +++ b/src/tox/tox_env/python/virtual_env/api.py @@ -132,7 +132,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: ARG # the base pythons are injected into the virtualenv_env_vars, so we don't need to use it here try: interpreter = self.creator.interpreter - except RuntimeError: # if can't find + except (FileNotFoundError, RuntimeError): # Unable to find the interpreter return None return PythonInfo( implementation=interpreter.implementation, diff --git a/tests/tox_env/python/test_python_api.py b/tests/tox_env/python/test_python_api.py index 159d9d772..e56d9d698 100644 --- a/tests/tox_env/python/test_python_api.py +++ b/tests/tox_env/python/test_python_api.py @@ -277,3 +277,10 @@ def test_list_installed_deps_explicit_cli( assert "pip==" in result.out else: assert "pip==" not in result.out + + +def test_usedevelop_with_nonexistent_basepython(tox_project: ToxProjectCreator) -> None: + ini = "[testenv]\nusedevelop = true\n[testenv:unused]\nbasepython = /nonexistent/bin/python" + project = tox_project({"tox.ini": ini}) + result = project.run() + assert result.code == 0