Commit 88cb8266 by Vladislav Committed by GitHub

refactor(test_env, conftest): move default venv flags to fixture (#3836)

Co-authored-by: Bartosz Sokorski <b.sokorski@gmail.com>
parent 9f955142
...@@ -476,3 +476,13 @@ def load_required_fixtures( ...@@ -476,3 +476,13 @@ def load_required_fixtures(
) -> None: ) -> None:
for fixture in required_fixtures: for fixture in required_fixtures:
fixture_copier(fixture) fixture_copier(fixture)
@pytest.fixture
def venv_flags_default() -> dict[str, bool]:
return {
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
}
...@@ -261,6 +261,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -261,6 +261,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
config: Config, config: Config,
mocker: MockerFixture, mocker: MockerFixture,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -283,16 +284,12 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -283,16 +284,12 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
m.assert_called_with( m.assert_called_with(
tmp_path / f"{venv_name}-py3.7", tmp_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3.7"), executable=Path("/usr/bin/python3.7"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7", prompt="simple-project-py3.7",
) )
envs_file = TOMLFile(tmp_path / "envs.toml") envs_file = TOMLFile(tmp_path / "envs.toml")
assert envs_file.exists() assert envs_file.exists()
envs: dict[str, Any] = envs_file.read() envs: dict[str, Any] = envs_file.read()
assert envs[venv_name]["minor"] == "3.7" assert envs[venv_name]["minor"] == "3.7"
...@@ -417,6 +414,7 @@ def test_activate_activates_different_virtualenv_with_envs_file( ...@@ -417,6 +414,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
config: Config, config: Config,
mocker: MockerFixture, mocker: MockerFixture,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -446,12 +444,7 @@ def test_activate_activates_different_virtualenv_with_envs_file( ...@@ -446,12 +444,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
m.assert_called_with( m.assert_called_with(
tmp_path / f"{venv_name}-py3.6", tmp_path / f"{venv_name}-py3.6",
executable=Path("/usr/bin/python3.6"), executable=Path("/usr/bin/python3.6"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.6", prompt="simple-project-py3.6",
) )
...@@ -471,6 +464,7 @@ def test_activate_activates_recreates_for_different_patch( ...@@ -471,6 +464,7 @@ def test_activate_activates_recreates_for_different_patch(
config: Config, config: Config,
mocker: MockerFixture, mocker: MockerFixture,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -511,12 +505,7 @@ def test_activate_activates_recreates_for_different_patch( ...@@ -511,12 +505,7 @@ def test_activate_activates_recreates_for_different_patch(
build_venv_m.assert_called_with( build_venv_m.assert_called_with(
tmp_path / f"{venv_name}-py3.7", tmp_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3.7"), executable=Path("/usr/bin/python3.7"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7", prompt="simple-project-py3.7",
) )
remove_venv_m.assert_called_with(tmp_path / f"{venv_name}-py3.7") remove_venv_m.assert_called_with(tmp_path / f"{venv_name}-py3.7")
...@@ -1139,6 +1128,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_ ...@@ -1139,6 +1128,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
mocker: MockerFixture, mocker: MockerFixture,
config_virtualenvs_path: Path, config_virtualenvs_path: Path,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -1160,12 +1150,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_ ...@@ -1160,12 +1150,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.7", config_virtualenvs_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3"), executable=Path("/usr/bin/python3"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7", prompt="simple-project-py3.7",
) )
...@@ -1205,6 +1190,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific ...@@ -1205,6 +1190,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
mocker: MockerFixture, mocker: MockerFixture,
config_virtualenvs_path: Path, config_virtualenvs_path: Path,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -1226,12 +1212,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific ...@@ -1226,12 +1212,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.9", config_virtualenvs_path / f"{venv_name}-py3.9",
executable=Path("/usr/bin/python3.9"), executable=Path("/usr/bin/python3.9"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.9", prompt="simple-project-py3.9",
) )
...@@ -1295,6 +1276,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility( ...@@ -1295,6 +1276,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
mocker: MockerFixture, mocker: MockerFixture,
config_virtualenvs_path: Path, config_virtualenvs_path: Path,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -1320,12 +1302,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility( ...@@ -1320,12 +1302,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor}", config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor}",
executable=None, executable=None,
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt=f"simple-project-py{version.major}.{version.minor}", prompt=f"simple-project-py{version.major}.{version.minor}",
) )
...@@ -1337,6 +1314,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable( ...@@ -1337,6 +1314,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
mocker: MockerFixture, mocker: MockerFixture,
config_virtualenvs_path: Path, config_virtualenvs_path: Path,
venv_name: str, venv_name: str,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -1364,12 +1342,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable( ...@@ -1364,12 +1342,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor - 1}", config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor - 1}",
executable=Path(f"python{version.major}.{version.minor - 1}"), executable=Path(f"python{version.major}.{version.minor - 1}"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt=f"simple-project-py{version.major}.{version.minor - 1}", prompt=f"simple-project-py{version.major}.{version.minor - 1}",
) )
...@@ -1408,6 +1381,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( ...@@ -1408,6 +1381,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
config: Config, config: Config,
tmp_path: Path, tmp_path: Path,
mocker: MockerFixture, mocker: MockerFixture,
venv_flags_default: dict[str, bool],
) -> None: ) -> None:
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
...@@ -1437,12 +1411,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( ...@@ -1437,12 +1411,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
m.assert_called_with( m.assert_called_with(
poetry.file.path.parent / ".venv", poetry.file.path.parent / ".venv",
executable=Path("/usr/bin/python3.7"), executable=Path("/usr/bin/python3.7"),
flags={ flags=venv_flags_default,
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7", prompt="simple-project-py3.7",
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment