Skip to content

Commit

Permalink
Replace == with is for comparison of cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kohr-h committed Jan 25, 2020
1 parent 85df6bb commit f0fd818
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Guido Wesdorp
Guoqiang Zhang
Harald Armin Massa
Henk-Jaap Wagenaar
Holger Kohr
Hugo van Kemenade
Hui Wang (coldnight)
Ian Bicking
Expand Down
5 changes: 5 additions & 0 deletions changelog/6497.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fix bug in the comparison of request key with cached key in fixture.

A construct ``if key == cached_key:`` can fail either because ``==`` is explicitly disallowed, or for, e.g., NumPy arrays, where the result of ``a == b`` cannot generally be converted to `bool`.
The implemented fix replaces `==` with ``is``.

4 changes: 3 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,9 @@ def execute(self, request):
cached_result = getattr(self, "cached_result", None)
if cached_result is not None:
result, cache_key, err = cached_result
if my_cache_key == cache_key:
# note: comparison with `==` can fail (or be expensive) for e.g.
# numpy arrays
if my_cache_key is cache_key:
if err is not None:
_, val, tb = err
raise val.with_traceback(tb)
Expand Down

0 comments on commit f0fd818

Please sign in to comment.