Skip to content

Commit c1dc7a8

Browse files
committed
New resolver incorrectly trys unneeded candidates
When the new resolver needs to upgrade a package, it puts the already-installed package in the middle of the candidate lists obtained from the index. But when doing it, the candidate list is eagerly consumed, causing pip to download all candidates.
1 parent 2b0b426 commit c1dc7a8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/functional/test_new_resolver.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,3 +1237,45 @@ def test_new_resolver_skip_inconsistent_metadata(script):
12371237

12381238
assert " different version in metadata: '2'" in result.stderr, str(result)
12391239
assert_installed(script, a="1")
1240+
1241+
1242+
@pytest.mark.parametrize(
1243+
"upgrade",
1244+
[True, False],
1245+
ids=["upgrade", "no-upgrade"],
1246+
)
1247+
def test_new_resolver_lazy_fetch_candidates(script, upgrade):
1248+
create_basic_wheel_for_package(script, "myuberpkg", "1")
1249+
create_basic_wheel_for_package(script, "myuberpkg", "2")
1250+
create_basic_wheel_for_package(script, "myuberpkg", "3")
1251+
1252+
# Install an old version first.
1253+
script.pip(
1254+
"install",
1255+
"--no-cache-dir", "--no-index",
1256+
"--find-links", script.scratch_path,
1257+
"myuberpkg==1",
1258+
)
1259+
1260+
# Now install the same package again, maybe with the upgrade flag.
1261+
if upgrade:
1262+
pip_upgrade_args = ["--upgrade"]
1263+
else:
1264+
pip_upgrade_args = []
1265+
result = script.pip(
1266+
"install",
1267+
"--no-cache-dir", "--no-index",
1268+
"--find-links", script.scratch_path,
1269+
"myuberpkg",
1270+
*pip_upgrade_args,
1271+
)
1272+
1273+
# pip should install the version preferred by the strategy...
1274+
if upgrade:
1275+
assert_installed(script, myuberpkg="3")
1276+
else:
1277+
assert_installed(script, myuberpkg="1")
1278+
1279+
# But should reach there in the best route possible, without trying
1280+
# candidates it does not need to.
1281+
assert "myuberpkg-2" not in result.stdout, str(result)

0 commit comments

Comments
 (0)