Skip to content

Commit

Permalink
refactor(test_env, conftest): move default venv flags to fixture (pyt…
Browse files Browse the repository at this point in the history
…hon-poetry#3836)

Co-authored-by: Bartosz Sokorski <b.sokorski@gmail.com>
  • Loading branch information
vlad0337187 and Secrus authored May 22, 2023
1 parent 9f95514 commit 88cb826
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 48 deletions.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
65 changes: 17 additions & 48 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
)

Expand All @@ -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"]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"]
Expand All @@ -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",
)

Expand Down Expand Up @@ -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"]
Expand All @@ -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",
)

Expand Down Expand Up @@ -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"]
Expand All @@ -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}",
)

Expand All @@ -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"]
Expand Down Expand Up @@ -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}",
)

Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
)

Expand Down

0 comments on commit 88cb826

Please sign in to comment.