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(
) -> None:
for fixture in required_fixtures:
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(
config: Config,
mocker: MockerFixture,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -283,16 +284,12 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
m.assert_called_with(
tmp_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3.7"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
prompt="simple-project-py3.7",
)
envs_file = TOMLFile(tmp_path / "envs.toml")
assert envs_file.exists()
envs: dict[str, Any] = envs_file.read()
assert envs[venv_name]["minor"] == "3.7"
......@@ -417,6 +414,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
config: Config,
mocker: MockerFixture,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -446,12 +444,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
m.assert_called_with(
tmp_path / f"{venv_name}-py3.6",
executable=Path("/usr/bin/python3.6"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
prompt="simple-project-py3.6",
)
......@@ -471,6 +464,7 @@ def test_activate_activates_recreates_for_different_patch(
config: Config,
mocker: MockerFixture,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -511,12 +505,7 @@ def test_activate_activates_recreates_for_different_patch(
build_venv_m.assert_called_with(
tmp_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3.7"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
prompt="simple-project-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_
mocker: MockerFixture,
config_virtualenvs_path: Path,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -1160,12 +1150,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.7",
executable=Path("/usr/bin/python3"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
prompt="simple-project-py3.7",
)
......@@ -1205,6 +1190,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
mocker: MockerFixture,
config_virtualenvs_path: Path,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -1226,12 +1212,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.9",
executable=Path("/usr/bin/python3.9"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
prompt="simple-project-py3.9",
)
......@@ -1295,6 +1276,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
mocker: MockerFixture,
config_virtualenvs_path: Path,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -1320,12 +1302,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor}",
executable=None,
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
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(
mocker: MockerFixture,
config_virtualenvs_path: Path,
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -1364,12 +1342,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py{version.major}.{version.minor - 1}",
executable=Path(f"python{version.major}.{version.minor - 1}"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
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(
config: Config,
tmp_path: Path,
mocker: MockerFixture,
venv_flags_default: dict[str, bool],
) -> None:
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
......@@ -1437,12 +1411,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
m.assert_called_with(
poetry.file.path.parent / ".venv",
executable=Path("/usr/bin/python3.7"),
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
flags=venv_flags_default,
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