Skip to content

Commit b9733f3

Browse files
committed
Add --no-build-isolation to tests
Most tests use setup.py-based test packages, and we want to avoid network access for building them.
1 parent 5bfdd4d commit b9733f3

28 files changed

+514
-117
lines changed

tests/functional/test_check.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def test_basic_check_missing_dependency(script: PipTestEnvironment) -> None:
3434
install_requires=["missing==0.1"],
3535
)
3636
# Let's install pkga without its dependency
37-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
37+
res = script.pip(
38+
"install", "--no-build-isolation", "--no-index", pkga_path, "--no-deps"
39+
)
3840
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
3941

4042
result = script.pip("check", expect_error=True)
@@ -53,7 +55,9 @@ def test_basic_check_broken_dependency(script: PipTestEnvironment) -> None:
5355
install_requires=["broken>=1.0"],
5456
)
5557
# Let's install pkga without its dependency
56-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
58+
res = script.pip(
59+
"install", "--no-build-isolation", "--no-index", pkga_path, "--no-deps"
60+
)
5761
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
5862

5963
# Setup broken==0.1
@@ -65,6 +69,7 @@ def test_basic_check_broken_dependency(script: PipTestEnvironment) -> None:
6569
# Let's install broken==0.1
6670
res = script.pip(
6771
"install",
72+
"--no-build-isolation",
6873
"--no-index",
6974
broken_path,
7075
"--no-warn-conflicts",
@@ -88,7 +93,9 @@ def test_basic_check_broken_dependency_and_missing_dependency(
8893
install_requires=["broken>=1.0"],
8994
)
9095
# Let's install pkga without its dependency
91-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
96+
res = script.pip(
97+
"install", "--no-build-isolation", "--no-index", pkga_path, "--no-deps"
98+
)
9299
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
93100

94101
# Setup broken==0.1
@@ -99,7 +106,9 @@ def test_basic_check_broken_dependency_and_missing_dependency(
99106
install_requires=["missing"],
100107
)
101108
# Let's install broken==0.1
102-
res = script.pip("install", "--no-index", broken_path, "--no-deps")
109+
res = script.pip(
110+
"install", "--no-build-isolation", "--no-index", broken_path, "--no-deps"
111+
)
103112
assert "Successfully installed broken-0.1" in res.stdout, str(res)
104113

105114
result = script.pip("check", expect_error=True)
@@ -122,7 +131,9 @@ def test_check_complicated_name_missing(script: PipTestEnvironment) -> None:
122131
)
123132

124133
# Without dependency
125-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
134+
result = script.pip(
135+
"install", "--no-build-isolation", "--no-index", package_a_path, "--no-deps"
136+
)
126137
assert (
127138
"Successfully installed package_A-1.0" in result.stdout
128139
or "Successfully installed package-A-1.0" in result.stdout
@@ -148,14 +159,17 @@ def test_check_complicated_name_broken(script: PipTestEnvironment) -> None:
148159
)
149160

150161
# With broken dependency
151-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
162+
result = script.pip(
163+
"install", "--no-build-isolation", "--no-index", package_a_path, "--no-deps"
164+
)
152165
assert (
153166
"Successfully installed package_A-1.0" in result.stdout
154167
or "Successfully installed package-A-1.0" in result.stdout
155168
), str(result)
156169

157170
result = script.pip(
158171
"install",
172+
"--no-build-isolation",
159173
"--no-index",
160174
dependency_b_path_incompatible,
161175
"--no-deps",
@@ -184,14 +198,17 @@ def test_check_complicated_name_clean(script: PipTestEnvironment) -> None:
184198
version="1.0",
185199
)
186200

187-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
201+
result = script.pip(
202+
"install", "--no-build-isolation", "--no-index", package_a_path, "--no-deps"
203+
)
188204
assert (
189205
"Successfully installed package_A-1.0" in result.stdout
190206
or "Successfully installed package-A-1.0" in result.stdout
191207
), str(result)
192208

193209
result = script.pip(
194210
"install",
211+
"--no-build-isolation",
195212
"--no-index",
196213
dependency_b_path,
197214
"--no-deps",
@@ -215,7 +232,9 @@ def test_check_considers_conditional_reqs(script: PipTestEnvironment) -> None:
215232
],
216233
)
217234

218-
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
235+
result = script.pip(
236+
"install", "--no-build-isolation", "--no-index", package_a_path, "--no-deps"
237+
)
219238
assert (
220239
"Successfully installed package_A-1.0" in result.stdout
221240
or "Successfully installed package-A-1.0" in result.stdout
@@ -238,7 +257,9 @@ def test_check_development_versions_are_also_considered(
238257
install_requires=["depend>=1.0"],
239258
)
240259
# Let's install pkga without its dependency
241-
res = script.pip("install", "--no-index", pkga_path, "--no-deps")
260+
res = script.pip(
261+
"install", "--no-build-isolation", "--no-index", pkga_path, "--no-deps"
262+
)
242263
assert "Successfully installed pkga-1.0" in res.stdout, str(res)
243264

244265
# Setup depend==1.1.0.dev0
@@ -250,6 +271,7 @@ def test_check_development_versions_are_also_considered(
250271
# Let's install depend==1.1.0.dev0
251272
res = script.pip(
252273
"install",
274+
"--no-build-isolation",
253275
"--no-index",
254276
depend_path,
255277
"--no-warn-conflicts",

tests/functional/test_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def test_entrypoints_work(entrypoint: str, script: PipTestEnvironment) -> None:
4545
)
4646

4747
# expect_temp because pip install will generate fake_pkg.egg-info
48-
script.pip("install", "-vvv", str(fake_pkg), expect_temp=True)
48+
script.pip(
49+
"install", "--no-build-isolation", "-vvv", str(fake_pkg), expect_temp=True
50+
)
4951
result = script.pip("-V")
5052
result2 = script.run("fake_pip", "-V", allow_stderr_warning=True)
5153
assert result.stdout == result2.stdout

tests/functional/test_download.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@ def test_download_wheel(script: PipTestEnvironment, data: TestData) -> None:
5454
"""
5555
Test using "pip download" to download a *.whl archive.
5656
"""
57+
# This test needs --no-build-isolation because `meta` depends on `simple`
58+
# which is a source distribution for which it needs to prepare metadata
59+
# to look for transitive dependencies.
5760
result = script.pip(
58-
"download", "--no-index", "-f", data.packages, "-d", ".", "meta"
61+
"download",
62+
"--no-build-isolation",
63+
"--no-index",
64+
"-f",
65+
data.packages,
66+
"-d",
67+
".",
68+
"meta",
5969
)
6070
result.did_create(Path("scratch") / "meta-1.0-py2.py3-none-any.whl")
6171
result.did_not_create(script.site_packages / "piptestpackage")
@@ -122,7 +132,14 @@ def test_download_should_download_wheel_deps(
122132
dep_filename = "translationstring-1.1.tar.gz"
123133
wheel_path = "/".join((data.find_links, wheel_filename))
124134
result = script.pip(
125-
"download", wheel_path, "-d", ".", "--find-links", data.find_links, "--no-index"
135+
"download",
136+
"--no-build-isolation",
137+
wheel_path,
138+
"-d",
139+
".",
140+
"--find-links",
141+
data.find_links,
142+
"--no-index",
126143
)
127144
result.did_create(Path("scratch") / wheel_filename)
128145
result.did_create(Path("scratch") / dep_filename)
@@ -687,8 +704,7 @@ def make_args(python_version: str) -> list[str]:
687704
args = make_args("33")
688705
result = script.pip(*args, expect_error=True)
689706
expected_err = (
690-
"ERROR: Package 'mypackage' requires a different Python: "
691-
"3.3.0 not in '==3.2'"
707+
"ERROR: Package 'mypackage' requires a different Python: 3.3.0 not in '==3.2'"
692708
)
693709
assert expected_err in result.stderr, f"stderr: {result.stderr}"
694710

@@ -978,6 +994,7 @@ def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(
978994

979995
result = script.pip(
980996
"download",
997+
"--no-build-isolation",
981998
"--prefer-binary",
982999
"--no-index",
9831000
"-f",
@@ -1006,6 +1023,7 @@ def test_prefer_binary_when_wheel_doesnt_satisfy_req_req_file(
10061023

10071024
result = script.pip(
10081025
"download",
1026+
"--no-build-isolation",
10091027
"--no-index",
10101028
"-f",
10111029
data.packages,
@@ -1023,6 +1041,7 @@ def test_download_prefer_binary_when_only_tarball_exists(
10231041
) -> None:
10241042
result = script.pip(
10251043
"download",
1044+
"--no-build-isolation",
10261045
"--prefer-binary",
10271046
"--no-index",
10281047
"-f",
@@ -1047,6 +1066,7 @@ def test_prefer_binary_when_only_tarball_exists_req_file(
10471066
)
10481067
result = script.pip(
10491068
"download",
1069+
"--no-build-isolation",
10501070
"--no-index",
10511071
"-f",
10521072
data.packages,
@@ -1078,6 +1098,7 @@ def test_download_file_url(
10781098

10791099
shared_script.pip(
10801100
"download",
1101+
"--no-build-isolation",
10811102
"-d",
10821103
str(download_dir),
10831104
"--no-index",
@@ -1102,7 +1123,12 @@ def test_download_file_url_existing_ok_download(
11021123
url = f"{simple_pkg.as_uri()}#sha256={sha256(downloaded_path_bytes).hexdigest()}"
11031124

11041125
shared_script.pip(
1105-
"download", "-d", str(download_dir), url, "--disable-pip-version-check"
1126+
"download",
1127+
"--no-build-isolation",
1128+
"-d",
1129+
str(download_dir),
1130+
url,
1131+
"--disable-pip-version-check",
11061132
)
11071133

11081134
assert downloaded_path_bytes == downloaded_path.read_bytes()
@@ -1123,6 +1149,7 @@ def test_download_file_url_existing_bad_download(
11231149

11241150
result = shared_script.pip(
11251151
"download",
1152+
"--no-build-isolation",
11261153
"-d",
11271154
str(download_dir),
11281155
url,
@@ -1159,6 +1186,7 @@ def test_download_http_url_bad_hash(
11591186

11601187
result = shared_script.pip(
11611188
"download",
1189+
"--no-build-isolation",
11621190
"-d",
11631191
str(download_dir),
11641192
url,
@@ -1187,7 +1215,13 @@ def test_download_editable(
11871215
requirements_path.write_text("-e " + editable_path + "\n")
11881216
download_dir = tmpdir / "download_dir"
11891217
script.pip(
1190-
"download", "--no-deps", "-r", str(requirements_path), "-d", str(download_dir)
1218+
"download",
1219+
"--no-build-isolation",
1220+
"--no-deps",
1221+
"-r",
1222+
str(requirements_path),
1223+
"-d",
1224+
str(download_dir),
11911225
)
11921226
downloads = os.listdir(download_dir)
11931227
assert len(downloads) == 1
@@ -1256,6 +1290,7 @@ def run_for_generated_index(
12561290
"""
12571291
pip_args = [
12581292
"download",
1293+
"--no-build-isolation",
12591294
"-d",
12601295
str(download_dir),
12611296
"-i",
@@ -1287,6 +1322,7 @@ def run_for_generated_index(
12871322
"""
12881323
pip_args = [
12891324
"download",
1325+
"--no-build-isolation",
12901326
"-d",
12911327
str(download_dir),
12921328
"-i",

tests/functional/test_freeze.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_freeze_editable_not_vcs(script: PipTestEnvironment) -> None:
209209
# Rename the .git directory so the directory is no longer recognized
210210
# as a VCS directory.
211211
os.rename(os.path.join(pkg_path, ".git"), os.path.join(pkg_path, ".bak"))
212-
script.pip("install", "-e", pkg_path)
212+
script.pip("install", "--no-build-isolation", "-e", pkg_path)
213213
result = script.pip("freeze")
214214

215215
# We need to apply os.path.normcase() to the path since that is what
@@ -231,7 +231,7 @@ def test_freeze_editable_git_with_no_remote(
231231
Test an editable Git install with no remote url.
232232
"""
233233
pkg_path = _create_test_package(script.scratch_path)
234-
script.pip("install", "-e", pkg_path)
234+
script.pip("install", "--no-build-isolation", "-e", pkg_path)
235235
result = script.pip("freeze")
236236

237237
if not deprecated_python:
@@ -595,7 +595,7 @@ def test_freeze_nested_vcs(
595595
os.fspath(src_path),
596596
expect_stderr=True,
597597
)
598-
script.pip("install", "-e", src_path, expect_stderr=True)
598+
script.pip("install", "--no-build-isolation", "-e", src_path, expect_stderr=True)
599599

600600
# Check the freeze output recognizes the inner VCS.
601601
result = script.pip("freeze", expect_stderr=True)
@@ -993,7 +993,7 @@ def test_freeze_direct_url_archive(
993993
script: PipTestEnvironment, shared_data: TestData
994994
) -> None:
995995
req = "simple @ " + shared_data.packages.joinpath("simple-2.0.tar.gz").as_uri()
996-
script.pip("install", req)
996+
script.pip("install", "--no-build-isolation", req)
997997
result = script.pip("freeze")
998998
assert req in result.stdout
999999

@@ -1037,7 +1037,7 @@ def test_freeze_pep610_editable(script: PipTestEnvironment) -> None:
10371037
is correctly frozeon as editable.
10381038
"""
10391039
pkg_path = _create_test_package(script.scratch_path, name="testpkg")
1040-
result = script.pip("install", pkg_path)
1040+
result = script.pip("install", "--no-build-isolation", pkg_path)
10411041
direct_url_path = result.get_created_direct_url_path("testpkg")
10421042
assert direct_url_path
10431043
# patch direct_url.json to simulate an editable install

0 commit comments

Comments
 (0)