Skip to content

Commit

Permalink
Let FixtureDef.cache_key use our new parameter key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tobias Deiminger committed Jan 23, 2022
1 parent b4482ac commit ace0069
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,10 @@ def execute(self, request: SubRequest) -> FixtureValue:

my_cache_key = self.cache_key(request)
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]
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:
_, val, tb = self.cached_result[2]
raise val.with_traceback(tb)
Expand All @@ -1037,7 +1037,7 @@ def execute(self, request: SubRequest) -> FixtureValue:
return result

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:
return "<FixtureDef argname={!r} scope={!r} baseid={!r}>".format(
Expand Down

0 comments on commit ace0069

Please sign in to comment.