Skip to content

Commit ef34fee

Browse files
committed
Selectively enable user site
The modern virtual environment structure does not allow us to enable "fake user site" while disabling the global site, so we need to do more fine-grained configuration to correctly set up test environments for each test case. With this done, we can also properly support the stdlib venv ad the test environment backend, since it basically works identically with modern virtualenv. The incompatible_with_test_venv is thus removed.
1 parent c3e3771 commit ef34fee

12 files changed

+70
-78
lines changed

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ xfail_strict = True
6363
markers =
6464
network: tests that need network
6565
incompatible_with_sysconfig
66-
incompatible_with_test_venv
6766
incompatible_with_venv
6867
no_auto_tempdir_manager
6968
unit: unit tests

tests/conftest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ def pytest_collection_modifyitems(config: Config, items: List[pytest.Function])
108108
if item.get_closest_marker("network") is not None:
109109
item.add_marker(pytest.mark.flaky(reruns=3, reruns_delay=2))
110110

111-
if item.get_closest_marker("incompatible_with_test_venv") and config.getoption(
112-
"--use-venv"
113-
):
114-
item.add_marker(pytest.mark.skip("Incompatible with test venv"))
115111
if (
116112
item.get_closest_marker("incompatible_with_venv")
117113
and sys.prefix != sys.base_prefix
@@ -474,9 +470,6 @@ def virtualenv_template(
474470
):
475471
(venv.bin / exe).unlink()
476472

477-
# Enable user site packages.
478-
venv.user_site_packages = True
479-
480473
# Rename original virtualenv directory to make sure
481474
# it's not reused by mistake from one of the copies.
482475
venv_template = tmpdir / "venv_template"
@@ -742,3 +735,8 @@ def mock_server() -> Iterator[MockServer]:
742735
@pytest.fixture
743736
def proxy(request: pytest.FixtureRequest) -> str:
744737
return request.config.getoption("proxy")
738+
739+
740+
@pytest.fixture
741+
def enable_user_site(virtualenv: VirtualEnvironment) -> None:
742+
virtualenv.user_site_packages = True

tests/functional/test_build_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
204204
assert result.stdout.strip() == "2.0", str(result)
205205

206206

207-
@pytest.mark.incompatible_with_test_venv
207+
@pytest.mark.usefixtures("enable_user_site")
208208
def test_build_env_isolation(script: PipTestEnvironment) -> None:
209209

210210
# Create dummy `pkg` wheel.

tests/functional/test_freeze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(
862862

863863

864864
@pytest.mark.network
865-
@pytest.mark.incompatible_with_test_venv
865+
@pytest.mark.usefixtures("enable_user_site")
866866
def test_freeze_user(
867867
script: PipTestEnvironment, virtualenv: VirtualEnvironment, data: TestData
868868
) -> None:
@@ -900,7 +900,7 @@ def test_freeze_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) -
900900

901901

902902
@pytest.mark.network
903-
@pytest.mark.incompatible_with_test_venv
903+
@pytest.mark.usefixtures("enable_user_site")
904904
def test_freeze_path_exclude_user(
905905
tmpdir: Path, script: PipTestEnvironment, data: TestData
906906
) -> None:

tests/functional/test_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_pep518_allows_missing_requires(
171171
assert result.files_created
172172

173173

174-
@pytest.mark.incompatible_with_test_venv
174+
@pytest.mark.usefixtures("enable_user_site")
175175
def test_pep518_with_user_pip(
176176
script: PipTestEnvironment, pip_src: Path, data: TestData, common_wheels: Path
177177
) -> None:
@@ -2106,7 +2106,7 @@ def test_target_install_ignores_distutils_config_install_prefix(
21062106
result.did_not_create(relative_script_base)
21072107

21082108

2109-
@pytest.mark.incompatible_with_test_venv
2109+
@pytest.mark.usefixtures("enable_user_site")
21102110
def test_user_config_accepted(script: PipTestEnvironment) -> None:
21112111
# user set in the config file is parsed as 0/1 instead of True/False.
21122112
# Check that this doesn't cause a problem.

tests/functional/test_install_reqs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ def test_install_local_with_subdirectory(script: PipTestEnvironment) -> None:
305305
result.assert_installed("version_subpkg.py", editable=False)
306306

307307

308-
@pytest.mark.incompatible_with_test_venv
309-
@pytest.mark.usefixtures("with_wheel")
308+
@pytest.mark.usefixtures("enable_user_site", "with_wheel")
310309
def test_wheel_user_with_prefix_in_pydistutils_cfg(
311310
script: PipTestEnvironment, data: TestData
312311
) -> None:

tests/functional/test_install_user.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def dist_in_site_packages(dist):
3535
)
3636

3737

38+
@pytest.mark.usefixtures("enable_user_site")
3839
class Tests_UserSite:
3940
@pytest.mark.network
40-
@pytest.mark.incompatible_with_test_venv
4141
def test_reset_env_system_site_packages_usersite(
4242
self, script: PipTestEnvironment
4343
) -> None:
@@ -57,7 +57,6 @@ def test_reset_env_system_site_packages_usersite(
5757
@pytest.mark.xfail
5858
@pytest.mark.network
5959
@need_svn
60-
@pytest.mark.incompatible_with_test_venv
6160
def test_install_subversion_usersite_editable_with_distribute(
6261
self, script: PipTestEnvironment, tmpdir: Path
6362
) -> None:
@@ -77,7 +76,6 @@ def test_install_subversion_usersite_editable_with_distribute(
7776
)
7877
result.assert_installed("INITools", use_user_site=True)
7978

80-
@pytest.mark.incompatible_with_test_venv
8179
@pytest.mark.usefixtures("with_wheel")
8280
def test_install_from_current_directory_into_usersite(
8381
self, script: PipTestEnvironment, data: TestData
@@ -123,7 +121,6 @@ def test_install_user_venv_nositepkgs_fails(
123121
)
124122

125123
@pytest.mark.network
126-
@pytest.mark.incompatible_with_test_venv
127124
def test_install_user_conflict_in_usersite(
128125
self, script: PipTestEnvironment
129126
) -> None:
@@ -148,7 +145,6 @@ def test_install_user_conflict_in_usersite(
148145
result2.did_create(egg_info_folder)
149146
assert not isfile(initools_v3_file), initools_v3_file
150147

151-
@pytest.mark.incompatible_with_test_venv
152148
def test_install_user_conflict_in_globalsite(
153149
self, virtualenv: VirtualEnvironment, script: PipTestEnvironment
154150
) -> None:
@@ -191,7 +187,6 @@ def test_install_user_conflict_in_globalsite(
191187
assert isdir(dist_info_folder)
192188
assert isdir(initools_folder)
193189

194-
@pytest.mark.incompatible_with_test_venv
195190
def test_upgrade_user_conflict_in_globalsite(
196191
self, virtualenv: VirtualEnvironment, script: PipTestEnvironment
197192
) -> None:
@@ -235,7 +230,6 @@ def test_upgrade_user_conflict_in_globalsite(
235230
assert isdir(dist_info_folder), result2.stdout
236231
assert isdir(initools_folder)
237232

238-
@pytest.mark.incompatible_with_test_venv
239233
def test_install_user_conflict_in_globalsite_and_usersite(
240234
self, virtualenv: VirtualEnvironment, script: PipTestEnvironment
241235
) -> None:
@@ -294,7 +288,6 @@ def test_install_user_conflict_in_globalsite_and_usersite(
294288
assert isdir(initools_folder)
295289

296290
@pytest.mark.network
297-
@pytest.mark.incompatible_with_test_venv
298291
def test_install_user_in_global_virtualenv_with_conflict_fails(
299292
self, script: PipTestEnvironment
300293
) -> None:

tests/functional/test_install_wheel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ def test_wheel_record_lines_have_updated_hash_for_scripts(
406406
]
407407

408408

409-
@pytest.mark.incompatible_with_test_venv
410-
@pytest.mark.usefixtures("with_wheel")
409+
@pytest.mark.usefixtures("enable_user_site", "with_wheel")
411410
def test_install_user_wheel(
412411
script: PipTestEnvironment, shared_data: TestData, tmpdir: Path
413412
) -> None:

tests/functional/test_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_multiple_exclude_and_normalization(
129129

130130

131131
@pytest.mark.network
132-
@pytest.mark.incompatible_with_test_venv
132+
@pytest.mark.usefixtures("enable_user_site")
133133
def test_user_flag(script: PipTestEnvironment, data: TestData) -> None:
134134
"""
135135
Test the behavior of --user flag in the list command
@@ -144,7 +144,7 @@ def test_user_flag(script: PipTestEnvironment, data: TestData) -> None:
144144

145145

146146
@pytest.mark.network
147-
@pytest.mark.incompatible_with_test_venv
147+
@pytest.mark.usefixtures("enable_user_site")
148148
def test_user_columns_flag(script: PipTestEnvironment, data: TestData) -> None:
149149
"""
150150
Test the behavior of --user --format=columns flags in the list command
@@ -656,7 +656,7 @@ def test_list_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) ->
656656
assert {"name": "simple", "version": "2.0"} in json_result
657657

658658

659-
@pytest.mark.incompatible_with_test_venv
659+
@pytest.mark.usefixtures("enable_user_site")
660660
def test_list_path_exclude_user(
661661
tmpdir: Path, script: PipTestEnvironment, data: TestData
662662
) -> None:

tests/functional/test_new_resolver_user.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.lib.venv import VirtualEnvironment
88

99

10-
@pytest.mark.incompatible_with_test_venv
10+
@pytest.mark.usefixtures("enable_user_site")
1111
def test_new_resolver_install_user(script: PipTestEnvironment) -> None:
1212
create_basic_wheel_for_package(script, "base", "0.1.0")
1313
result = script.pip(
@@ -22,7 +22,7 @@ def test_new_resolver_install_user(script: PipTestEnvironment) -> None:
2222
result.did_create(script.user_site / "base")
2323

2424

25-
@pytest.mark.incompatible_with_test_venv
25+
@pytest.mark.usefixtures("enable_user_site")
2626
def test_new_resolver_install_user_satisfied_by_global_site(
2727
script: PipTestEnvironment,
2828
) -> None:
@@ -53,7 +53,7 @@ def test_new_resolver_install_user_satisfied_by_global_site(
5353
result.did_not_create(script.user_site / "base")
5454

5555

56-
@pytest.mark.incompatible_with_test_venv
56+
@pytest.mark.usefixtures("enable_user_site")
5757
def test_new_resolver_install_user_conflict_in_user_site(
5858
script: PipTestEnvironment,
5959
) -> None:
@@ -91,7 +91,7 @@ def test_new_resolver_install_user_conflict_in_user_site(
9191
result.did_not_create(base_2_dist_info)
9292

9393

94-
@pytest.mark.incompatible_with_test_venv
94+
@pytest.mark.usefixtures("enable_user_site")
9595
def test_new_resolver_install_user_in_virtualenv_with_conflict_fails(
9696
script: PipTestEnvironment,
9797
) -> None:
@@ -141,8 +141,7 @@ def dist_in_site_packages(dist):
141141
)
142142

143143

144-
@pytest.mark.incompatible_with_test_venv
145-
@pytest.mark.usefixtures("patch_dist_in_site_packages")
144+
@pytest.mark.usefixtures("enable_user_site", "patch_dist_in_site_packages")
146145
def test_new_resolver_install_user_reinstall_global_site(
147146
script: PipTestEnvironment,
148147
) -> None:
@@ -177,8 +176,7 @@ def test_new_resolver_install_user_reinstall_global_site(
177176
assert "base" in site_packages_content
178177

179178

180-
@pytest.mark.incompatible_with_test_venv
181-
@pytest.mark.usefixtures("patch_dist_in_site_packages")
179+
@pytest.mark.usefixtures("enable_user_site", "patch_dist_in_site_packages")
182180
def test_new_resolver_install_user_conflict_in_global_site(
183181
script: PipTestEnvironment,
184182
) -> None:
@@ -215,8 +213,7 @@ def test_new_resolver_install_user_conflict_in_global_site(
215213
assert "base-1.0.0.dist-info" in site_packages_content
216214

217215

218-
@pytest.mark.incompatible_with_test_venv
219-
@pytest.mark.usefixtures("patch_dist_in_site_packages")
216+
@pytest.mark.usefixtures("enable_user_site", "patch_dist_in_site_packages")
220217
def test_new_resolver_install_user_conflict_in_global_and_user_sites(
221218
script: PipTestEnvironment,
222219
) -> None:

tests/functional/test_uninstall_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from tests.lib.wheel import make_wheel
1212

1313

14-
@pytest.mark.incompatible_with_test_venv
14+
@pytest.mark.usefixtures("enable_user_site")
1515
class Tests_UninstallUserSite:
1616
@pytest.mark.network
1717
def test_uninstall_from_usersite(self, script: PipTestEnvironment) -> None:

0 commit comments

Comments
 (0)