Skip to content

Commit e5fd9e4

Browse files
authored
Merge pull request #13714 from ichard26/test/improve-slow-tests
Eliminate network access from some download, upgrade, and list tests
2 parents 87031ab + 2dd94f4 commit e5fd9e4

File tree

4 files changed

+55
-88
lines changed

4 files changed

+55
-88
lines changed

tests/functional/test_download.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -144,55 +144,29 @@ def test_download_should_download_wheel_deps(
144144
result.did_create(Path("scratch") / dep_filename)
145145

146146

147-
@pytest.mark.network
148-
def test_download_should_skip_existing_files(script: PipTestEnvironment) -> None:
147+
def test_download_should_skip_existing_files(
148+
script: PipTestEnvironment, data: TestData
149+
) -> None:
149150
"""
150151
It should not download files already existing in the scratch dir
151152
"""
152-
script.scratch_path.joinpath("test-req.txt").write_text(
153-
textwrap.dedent(
154-
"""
155-
INITools==0.1
156-
"""
157-
)
158-
)
159-
160-
result = script.pip(
161-
"download",
162-
"-r",
163-
script.scratch_path / "test-req.txt",
164-
"-d",
165-
".",
166-
)
167-
result.did_create(Path("scratch") / "INITools-0.1.tar.gz")
168-
result.did_not_create(script.site_packages / "initools")
153+
req_file = script.temporary_file("reqs.txt", "simplewheel==1.0")
154+
result = script.pip("download", "-r", req_file, "-f", data.packages, "--no-index")
155+
result.did_create(Path("scratch") / "simplewheel-1.0-py2.py3-none-any.whl")
156+
result.did_not_create(script.site_packages / "simplewheel")
169157

170158
# adding second package to test-req.txt
171-
script.scratch_path.joinpath("test-req.txt").write_text(
172-
textwrap.dedent(
173-
"""
174-
INITools==0.1
175-
python-openid==2.2.5
176-
"""
177-
)
178-
)
159+
script.temporary_file(req_file, "simplewheel==1.0\nsimple.dist")
179160

180161
# only the second package should be downloaded
181-
result = script.pip(
182-
"download",
183-
"-r",
184-
script.scratch_path / "test-req.txt",
185-
"-d",
186-
".",
187-
)
188-
openid_tarball_prefix = str(Path("scratch") / "python-openid-")
162+
result = script.pip("download", "-r", req_file, "-f", data.packages, "--no-index")
189163
assert any(
190-
os.fspath(path).startswith(openid_tarball_prefix)
164+
os.fspath(path).startswith(str(Path("scratch") / "simple.dist"))
191165
for path in result.files_created
192166
)
193-
result.did_not_create(Path("scratch") / "INITools-0.1.tar.gz")
194-
result.did_not_create(script.site_packages / "initools")
195-
result.did_not_create(script.site_packages / "openid")
167+
result.did_not_create(Path("scratch") / "simplewheel-1.0-py2.py3-none-any.whl")
168+
result.did_not_create(script.site_packages / "simplewheel")
169+
result.did_not_create(script.site_packages / "simpledist")
196170

197171

198172
@pytest.mark.network

tests/functional/test_install_upgrade.py

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
from tests.lib.wheel import make_wheel
1818

1919

20-
@pytest.mark.network
2120
def test_no_upgrade_unless_requested(script: PipTestEnvironment) -> None:
2221
"""
2322
No upgrade if not specifically requested.
2423
2524
"""
26-
script.pip("install", "INITools==0.1")
27-
result = script.pip("install", "INITools")
25+
script.pip_install_local("simplewheel==1.0")
26+
result = script.pip_install_local("simplewheel")
2827
assert (
2928
not result.files_created
3029
), "pip install INITools upgraded when it should not have"
@@ -135,29 +134,27 @@ def test_eager_does_upgrade_dependencies_when_no_longer_satisfied(
135134
), "should have uninstalled simple==1.0"
136135

137136

138-
@pytest.mark.network
139137
def test_upgrade_to_specific_version(script: PipTestEnvironment) -> None:
140138
"""
141139
It does upgrade to specific version requested.
142140
143141
"""
144-
script.pip("install", "INITools==0.1")
145-
result = script.pip("install", "INITools==0.2")
142+
script.pip_install_local("simplewheel==1.0")
143+
result = script.pip_install_local("simplewheel==2.0")
146144
assert result.files_created, "pip install with specific version did not upgrade"
147-
assert script.site_packages / "initools-0.1.dist-info" in result.files_deleted
148-
result.did_create(script.site_packages / "initools-0.2.dist-info")
145+
assert script.site_packages / "simplewheel-1.0.dist-info" in result.files_deleted
146+
result.did_create(script.site_packages / "simplewheel-2.0.dist-info")
149147

150148

151-
@pytest.mark.network
152149
def test_upgrade_if_requested(script: PipTestEnvironment) -> None:
153150
"""
154151
And it does upgrade if requested.
155152
156153
"""
157-
script.pip("install", "INITools==0.1")
158-
result = script.pip("install", "--upgrade", "INITools")
154+
script.pip_install_local("simplewheel==1.0")
155+
result = script.pip_install_local("--upgrade", "simplewheel")
159156
assert result.files_created, "pip install --upgrade did not upgrade"
160-
result.did_not_create(script.site_packages / "initools-0.1.dist-info")
157+
result.did_not_create(script.site_packages / "simplewheel-1.0.dist-info")
161158

162159

163160
def test_upgrade_with_newest_already_installed(
@@ -192,31 +189,29 @@ def test_upgrade_with_newest_already_installed(
192189
assert msg in result.stdout, result.stdout
193190

194191

195-
@pytest.mark.network
196192
def test_upgrade_force_reinstall_newest(script: PipTestEnvironment) -> None:
197193
"""
198194
Force reinstallation of a package even if it is already at its newest
199195
version if --force-reinstall is supplied.
200196
"""
201-
result = script.pip("install", "INITools")
202-
result.did_create(script.site_packages / "initools")
203-
result2 = script.pip("install", "--upgrade", "--force-reinstall", "INITools")
204-
assert result2.files_updated, "upgrade to INITools 0.3 failed"
205-
result3 = script.pip("uninstall", "initools", "-y")
197+
result = script.pip_install_local("simplewheel")
198+
result.did_create(script.site_packages / "simplewheel")
199+
result2 = script.pip_install_local("--upgrade", "--force-reinstall", "simplewheel")
200+
assert result2.files_updated, "upgrade to simplewheel 2.0 failed"
201+
result3 = script.pip("uninstall", "simplewheel", "-y")
206202
assert_all_changes(result, result3, [script.venv / "build", "cache"])
207203

208204

209-
@pytest.mark.network
210205
def test_uninstall_before_upgrade(script: PipTestEnvironment) -> None:
211206
"""
212207
Automatic uninstall-before-upgrade.
213208
214209
"""
215-
result = script.pip("install", "INITools==0.2")
216-
result.did_create(script.site_packages / "initools")
217-
result2 = script.pip("install", "INITools==0.3")
218-
assert result2.files_created, "upgrade to INITools 0.3 failed"
219-
result3 = script.pip("uninstall", "initools", "-y")
210+
result = script.pip_install_local("simplewheel==1.0")
211+
result.did_create(script.site_packages / "simplewheel")
212+
result2 = script.pip_install_local("simplewheel==2.0")
213+
assert result2.files_created, "upgrade to simplewheel 2.0 failed"
214+
result3 = script.pip("uninstall", "simplewheel", "-y")
220215
assert_all_changes(result, result3, [script.venv / "build", "cache"])
221216

222217

@@ -329,30 +324,30 @@ def test_uninstall_rollback(script: PipTestEnvironment, data: TestData) -> None:
329324
)
330325

331326

332-
@pytest.mark.network
333-
def test_should_not_install_always_from_cache(script: PipTestEnvironment) -> None:
327+
def test_should_not_install_always_from_cache(
328+
script: PipTestEnvironment, data: TestData
329+
) -> None:
334330
"""
335331
If there is an old cached package, pip should download the newer version
336332
Related to issue #175
337333
"""
338-
script.pip("install", "INITools==0.2")
339-
script.pip("uninstall", "-y", "INITools")
340-
result = script.pip("install", "INITools==0.1")
341-
result.did_not_create(script.site_packages / "initools-0.2.dist-info")
342-
result.did_create(script.site_packages / "initools-0.1.dist-info")
334+
script.pip_install_local("simplewheel==2.0")
335+
script.pip("uninstall", "-y", "simplewheel")
336+
result = script.pip_install_local("simplewheel==1.0")
337+
result.did_not_create(script.site_packages / "simplewheel-2.0.dist-info")
338+
result.did_create(script.site_packages / "simplewheel-1.0.dist-info")
343339

344340

345-
@pytest.mark.network
346341
def test_install_with_ignoreinstalled_requested(script: PipTestEnvironment) -> None:
347342
"""
348343
Test old conflicting package is completely ignored
349344
"""
350-
script.pip("install", "INITools==0.1")
351-
result = script.pip("install", "-I", "INITools==0.3")
345+
script.pip_install_local("simplewheel==1.0")
346+
result = script.pip_install_local("-I", "simplewheel==2.0")
352347
assert result.files_created, "pip install -I did not install"
353348
# both the old and new metadata should be present.
354-
assert os.path.exists(script.site_packages_path / "initools-0.1.dist-info")
355-
assert os.path.exists(script.site_packages_path / "initools-0.3.dist-info")
349+
assert os.path.exists(script.site_packages_path / "simplewheel-1.0.dist-info")
350+
assert os.path.exists(script.site_packages_path / "simplewheel-2.0.dist-info")
356351

357352

358353
@pytest.mark.network

tests/functional/test_list.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,36 +130,32 @@ def test_multiple_exclude_and_normalization(
130130
assert "pip" not in result.stdout
131131

132132

133-
@pytest.mark.network
134133
@pytest.mark.usefixtures("enable_user_site")
135134
def test_user_flag(script: PipTestEnvironment, data: TestData) -> None:
136135
"""
137136
Test the behavior of --user flag in the list command
138137
139138
"""
140-
script.pip("download", "setuptools", "wheel", "-d", data.packages)
141-
script.pip("install", "-f", data.find_links, "--no-index", "simple==1.0")
142-
script.pip("install", "-f", data.find_links, "--no-index", "--user", "simple2==2.0")
139+
script.pip_install_local("simplewheel==1.0")
140+
script.pip_install_local("--user", "simple.dist==0.1")
143141
result = script.pip("list", "--user", "--format=json")
144-
assert {"name": "simple", "version": "1.0"} not in json.loads(result.stdout)
145-
assert {"name": "simple2", "version": "2.0"} in json.loads(result.stdout)
142+
assert {"name": "simplewheel", "version": "1.0"} not in json.loads(result.stdout)
143+
assert {"name": "simple.dist", "version": "0.1"} in json.loads(result.stdout)
146144

147145

148-
@pytest.mark.network
149146
@pytest.mark.usefixtures("enable_user_site")
150147
def test_user_columns_flag(script: PipTestEnvironment, data: TestData) -> None:
151148
"""
152149
Test the behavior of --user --format=columns flags in the list command
153150
154151
"""
155-
script.pip("download", "setuptools", "wheel", "-d", data.packages)
156-
script.pip("install", "-f", data.find_links, "--no-index", "simple==1.0")
157-
script.pip("install", "-f", data.find_links, "--no-index", "--user", "simple2==2.0")
152+
script.pip_install_local("simplewheel==1.0")
153+
script.pip_install_local("--user", "simple.dist==0.1")
158154
result = script.pip("list", "--user", "--format=columns")
159155
assert "Package" in result.stdout
160156
assert "Version" in result.stdout
161-
assert "simple2 (2.0)" not in result.stdout
162-
assert "simple2 2.0" in result.stdout, str(result)
157+
assert "simple.dist (2.0)" not in result.stdout
158+
assert "simple.dist 0.1" in result.stdout, str(result)
163159

164160

165161
@pytest.mark.network

tests/lib/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ def assert_installed_editable(self, dist_name: str) -> None:
758758
and x.get("editable_project_location")
759759
)
760760

761-
def temporary_file(self, filename: str, contents: str) -> pathlib.Path:
761+
def temporary_file(
762+
self, filename: str | pathlib.Path, contents: str
763+
) -> pathlib.Path:
762764
"""Create a temporary file with the given filename and contents."""
763765
path = self.scratch_path.joinpath(filename)
764766
create_file(path, contents)

0 commit comments

Comments
 (0)