Skip to content

Commit 5377ff1

Browse files
Tobias Deimingerbluetech
authored andcommitted
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.
1 parent c1aaede commit 5377ff1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/_pytest/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,10 @@ def execute(self, request: SubRequest) -> FixtureValue:
10171017

10181018
my_cache_key = self.cache_key(request)
10191019
if self.cached_result is not None:
1020-
# note: comparison with `==` can fail (or be expensive) for e.g.
1021-
# numpy arrays (#6497).
10221020
cache_key = self.cached_result[1]
1023-
if my_cache_key is cache_key:
1021+
# Note: Comparison with `==` may be implemented as (possibly expensive)
1022+
# deep by-value comparison. See _pytest.python.SafeHashWrapper for details.
1023+
if my_cache_key == cache_key:
10241024
if self.cached_result[2] is not None:
10251025
_, val, tb = self.cached_result[2]
10261026
raise val.with_traceback(tb)
@@ -1037,7 +1037,7 @@ def execute(self, request: SubRequest) -> FixtureValue:
10371037
return result
10381038

10391039
def cache_key(self, request: SubRequest) -> object:
1040-
return request.param_index if not hasattr(request, "param") else request.param
1040+
return request.param_key
10411041

10421042
def __repr__(self) -> str:
10431043
return "<FixtureDef argname={!r} scope={!r} baseid={!r}>".format(

0 commit comments

Comments
 (0)