-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parametrized fixtures being incorrectly re-instantiated #6962
Labels
topic: fixtures
anything involving fixtures directly or indirectly
type: regression
indicates a problem that was introduced in a release which was working previously
Comments
Zac-HD
added
topic: fixtures
anything involving fixtures directly or indirectly
type: regression
indicates a problem that was introduced in a release which was working previously
labels
Mar 24, 2020
I can confirm that I am also seeing this exact problem. After upgrading from 5.3.2 to 6.2.5. |
I can also confirm that reverting the "is" comparison back to "==" fixes this issue on 6.2.5. |
DH-MP
added a commit
to DH-MP/pytest
that referenced
this issue
Mar 4, 2022
Revert due to pytest-dev#6962.
0xDEC0DE
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 11, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
0xDEC0DE
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 11, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
0xDEC0DE
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 11, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
0xDEC0DE
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 11, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
0xDEC0DE
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 12, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
nicoddemus
pushed a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 17, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Attempt to restore the previous behavior, while also retaining the fix for the bug. Fixes: Issue pytest-dev#6962
0xDEC0DE
added a commit
to 0xDEC0DE/pytest
that referenced
this issue
Jul 17, 2024
The fix for Issue pytest-dev#6541 caused regression where cache hits became cache misses, unexpectedly. Fixes pytest-dev#6962 --------- Co-authored-by: Nicolas Simonds <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]> Co-authored-by: Ran Benita <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
topic: fixtures
anything involving fixtures directly or indirectly
type: regression
indicates a problem that was introduced in a release which was working previously
Bug description
The change in d282424 has significantly altered the way parametrized fixtures are cached by changing the operator used to compare them: using
is
instead of__eq__
. For fixtures that are parametrized using strings (and potentially other parameter types) this has caused strange (read: unexpected) behavior where fixtures are recreated when the user would expect them to be cached and re-used. Since re-use of expensive-to-set-up fixtures is precisely why fixtures exists, I believe this is bug and that the change above should be reverted or at least adapted.This bug obviously doesn't affect pytest versions without the commit d282424; i.e. pytest < 5.4.0.
Example
The behavior described above can be illustrated by the following code:
The result of running this with pyrest 5.4.1 is:
Note how the fixture is created 3 times and not 2 times.
Now compare this with the following slightly modified code (the only difference is the way the value of
param
is created inpytest_generate_tests
):Note how the fixture is now, as one would expected, instantiated only twice.
Conclusion
I think it's dangerous to use
is
to compare the values of objects since it compares addresses, as illustrated above. Usingis
might be the right thing to do for Numpy arrays but not for the general case. As a result I suggest reverting the change d282424, maybe usingis
to compare Numpy arrays specifically and continuing to use__eq__
for all other objects.The text was updated successfully, but these errors were encountered: