Let FixtureDef.cache_key use our new parameter key

The FixtureDef cache must agree with reorder_items about what parmeters
are the same.

The new param key must (and can) be compared by value, so we change from
"is" to "==" in FixtureDef.execute.
This commit is contained in:
Tobias Deiminger 2021-12-16 21:03:27 +01:00 committed by Ran Benita
parent c1aaede59b
commit 5377ff1067
1 changed files with 4 additions and 4 deletions

View File

@ -1017,10 +1017,10 @@ class FixtureDef(Generic[FixtureValue]):
my_cache_key = self.cache_key(request) my_cache_key = self.cache_key(request)
if self.cached_result is not None: if self.cached_result is not None:
# note: comparison with `==` can fail (or be expensive) for e.g.
# numpy arrays (#6497).
cache_key = self.cached_result[1] cache_key = self.cached_result[1]
if my_cache_key is cache_key: # Note: Comparison with `==` may be implemented as (possibly expensive)
# deep by-value comparison. See _pytest.python.SafeHashWrapper for details.
if my_cache_key == cache_key:
if self.cached_result[2] is not None: if self.cached_result[2] is not None:
_, val, tb = self.cached_result[2] _, val, tb = self.cached_result[2]
raise val.with_traceback(tb) raise val.with_traceback(tb)
@ -1037,7 +1037,7 @@ class FixtureDef(Generic[FixtureValue]):
return result return result
def cache_key(self, request: SubRequest) -> object: def cache_key(self, request: SubRequest) -> object:
return request.param_index if not hasattr(request, "param") else request.param return request.param_key
def __repr__(self) -> str: def __repr__(self) -> str:
return "<FixtureDef argname={!r} scope={!r} baseid={!r}>".format( return "<FixtureDef argname={!r} scope={!r} baseid={!r}>".format(