|
20 | 20 | from poetry.utils.env import EnvCommandError
|
21 | 21 | from poetry.utils.env import EnvManager
|
22 | 22 | from poetry.utils.env import GenericEnv
|
| 23 | +from poetry.utils.env import InvalidCurrentPythonVersionError |
23 | 24 | from poetry.utils.env import NoCompatiblePythonVersionFound
|
24 | 25 | from poetry.utils.env import SystemEnv
|
25 | 26 | from poetry.utils.env import VirtualEnv
|
@@ -882,6 +883,28 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
|
882 | 883 | )
|
883 | 884 |
|
884 | 885 |
|
| 886 | +def test_create_venv_fails_if_current_python_version_is_not_supported(manager, poetry): |
| 887 | + if "VIRTUAL_ENV" in os.environ: |
| 888 | + del os.environ["VIRTUAL_ENV"] |
| 889 | + |
| 890 | + manager.create_venv(NullIO()) |
| 891 | + |
| 892 | + version = Version.parse(".".join(str(c) for c in sys.version_info[:3])) |
| 893 | + poetry.package.python_versions = "~{}".format( |
| 894 | + ".".join(str(c) for c in (version.major, version.minor + 1, 0)) |
| 895 | + ) |
| 896 | + |
| 897 | + with pytest.raises(InvalidCurrentPythonVersionError) as e: |
| 898 | + manager.create_venv(NullIO()) |
| 899 | + |
| 900 | + expected_message = ( |
| 901 | + "Current Python version (3.9.5) is not allowed by the project (~3.10.0).\n" |
| 902 | + 'Please change python executable via the "env use" command.' |
| 903 | + ) |
| 904 | + |
| 905 | + assert expected_message == str(e.value) |
| 906 | + |
| 907 | + |
885 | 908 | def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
|
886 | 909 | manager, poetry, config, tmp_dir, mocker
|
887 | 910 | ):
|
|
0 commit comments