Skip to content

Commit

Permalink
Fix fallback to other interpreters when specifying a patchlevel.
Browse files Browse the repository at this point in the history
When a project specifies a narrow range for the supported python
versions, i.e. "python ~= 3.6.1" and the current interpreter falls
outside of that range, the fallback code fails to test an available
python3.6 interpreter because of a too strict a test.
  • Loading branch information
jaharkes committed Dec 10, 2020
1 parent bf30ca6 commit a59959a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def create_venv(
supported_python
):
continue
elif not supported_python.allows_all(
elif not supported_python.allows_any(
parse_constraint(python_to_try + ".*")
):
continue
Expand Down
29 changes: 29 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,32 @@ def test_venv_has_correct_paths(tmp_venv):
assert paths.get("platlib") is not None
assert paths.get("scripts") is not None
assert tmp_venv.site_packages.path == Path(paths["purelib"])


def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
manager, poetry, config, mocker, config_virtualenvs_path
):
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

poetry.package.python_versions = "~3.5.1"
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))

check_output = mocker.patch(
"subprocess.check_output",
side_effect=lambda cmd, *args, **kwargs: str("3.5.12" if "python3.5" in cmd else "3.7.1")
)
m = mocker.patch(
"poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
)

manager.create_venv(NullIO()
)

assert check_output.called
m.assert_called_with(
config_virtualenvs_path
/ "{}-py3.5".format(venv_name),
executable="python3.5",
flags={"always-copy": False},
)

0 comments on commit a59959a

Please sign in to comment.