From 761433cee8ad0146bf38b2736a22c91d1dd63615 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 2 Oct 2020 19:55:05 +0800 Subject: [PATCH] Eliminate len() usage in tests --- .../_internal/resolution/resolvelib/found_candidates.py | 9 ++++----- tests/unit/resolution_resolvelib/test_requirement.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/found_candidates.py b/src/pip/_internal/resolution/resolvelib/found_candidates.py index 491290466..db8232240 100644 --- a/src/pip/_internal/resolution/resolvelib/found_candidates.py +++ b/src/pip/_internal/resolution/resolvelib/found_candidates.py @@ -83,13 +83,12 @@ class FoundCandidates(collections_abc.Sequence): candidates = _insert_installed(self._installed, self._get_others()) return _deduplicated_by_version(candidates) - @lru_cache(maxsize=1) def __len__(self): # type: () -> int - # Implement to satisfy the ABC check and used in tests. This is not - # needed by the resolver, and should not be used by the provider either - # (for performance reasons). - return sum(1 for _ in self) + # Implemented to satisfy the ABC check. This is not needed by the + # resolver, and should not be used by the provider either (for + # performance reasons). + raise NotImplementedError("don't do this") @lru_cache(maxsize=1) def __bool__(self): diff --git a/tests/unit/resolution_resolvelib/test_requirement.py b/tests/unit/resolution_resolvelib/test_requirement.py index 48c5f7347..6149fd1ae 100644 --- a/tests/unit/resolution_resolvelib/test_requirement.py +++ b/tests/unit/resolution_resolvelib/test_requirement.py @@ -61,7 +61,7 @@ def test_new_resolver_correct_number_of_matches(test_cases, factory): matches = factory.find_candidates( [req], Constraint.empty(), prefers_installed=False, ) - assert len(list(matches)) == match_count + assert sum(1 for _ in matches) == match_count def test_new_resolver_candidates_match_requirement(test_cases, factory):