Skip to content

Commit

Permalink
New resolver incorrectly tries unneeded candidates
Browse files Browse the repository at this point in the history
When the new resolver needs to upgrade a package, it puts the
already-installed package in the middle of the candidate list obtained
from indexes. But when doing it, the candidate list is eagerly consumed,
causing pip to download all candidates.
  • Loading branch information
uranusjr committed Dec 26, 2020
1 parent 41a3008 commit 92ad717
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,45 @@ def test_new_resolver_skip_inconsistent_metadata(script):

assert " different version in metadata: '2'" in result.stderr, str(result)
assert_installed(script, a="1")


@pytest.mark.parametrize(
"upgrade",
[True, False],
ids=["upgrade", "no-upgrade"],
)
def test_new_resolver_lazy_fetch_candidates(script, upgrade):
create_basic_wheel_for_package(script, "myuberpkg", "1")
create_basic_wheel_for_package(script, "myuberpkg", "2")
create_basic_wheel_for_package(script, "myuberpkg", "3")

# Install an old version first.
script.pip(
"install",
"--no-cache-dir", "--no-index",
"--find-links", script.scratch_path,
"myuberpkg==1",
)

# Now install the same package again, maybe with the upgrade flag.
if upgrade:
pip_upgrade_args = ["--upgrade"]
else:
pip_upgrade_args = []
result = script.pip(
"install",
"--no-cache-dir", "--no-index",
"--find-links", script.scratch_path,
"myuberpkg",
*pip_upgrade_args # Trailing comma fails on Python 2.
)

# pip should install the version preferred by the strategy...
if upgrade:
assert_installed(script, myuberpkg="3")
else:
assert_installed(script, myuberpkg="1")

# But should reach there in the best route possible, without trying
# candidates it does not need to.
assert "myuberpkg-2" not in result.stdout, str(result)

0 comments on commit 92ad717

Please sign in to comment.