Skip to content

Commit fa7147b

Browse files
committed
Change comparison order
1 parent 3153ab2 commit fa7147b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/_pytest/fixtures.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,18 +1053,16 @@ def execute(self, request: SubRequest) -> FixtureValue:
10531053
requested_fixtures_that_should_finalize_us.append(fixturedef)
10541054

10551055
# Check for (and return) cached value/exception.
1056-
my_cache_key = self.cache_key(request)
10571056
if self.cached_result is not None:
1057+
request_cache_key = self.cache_key(request)
10581058
cache_key = self.cached_result[1]
1059-
1060-
# First attempt to use 'is' for performance reasons (for example numpy arrays (#6497)).
1061-
cache_hit = my_cache_key is cache_key
1062-
if not cache_hit:
1063-
# If they are not the same, fallback to a bool comparison (#12600).
1064-
try:
1065-
cache_hit = bool(my_cache_key == cache_key)
1066-
except (ValueError, RuntimeError):
1067-
cache_hit = False
1059+
try:
1060+
# Attempt to make a normal == check: this might fail for objects
1061+
# which do not implement the standard comparison (like numpy arrays -- #6497).
1062+
cache_hit = bool(request_cache_key == cache_key)
1063+
except (ValueError, RuntimeError):
1064+
# If the comparison raises, use 'is' as fallback.
1065+
cache_hit = request_cache_key is cache_key
10681066

10691067
if cache_hit:
10701068
if self.cached_result[2] is not None:

0 commit comments

Comments
 (0)