From b891a9260dec2fca002dcbce1c42f4ba3effd244 Mon Sep 17 00:00:00 2001 From: Tobias Deiminger Date: Thu, 16 Dec 2021 21:03:27 +0100 Subject: [PATCH] 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. --- src/_pytest/fixtures.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 701badd4865..9176493dd7e 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -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) @@ -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 "".format(