File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ Fixed internal error when test functions were patched with objects that cannot be compared
2
+ for truth values against others, like ``numpy `` arrays.
Original file line number Diff line number Diff line change @@ -178,6 +178,34 @@ def test_hello_mock(self, abspath):
178
178
reprec = testdir .inline_run ()
179
179
reprec .assertoutcome (passed = 2 )
180
180
181
+ def test_mock_sentinel_check_against_numpy_like (self , testdir ):
182
+ """Ensure our function that detects mock arguments compares against sentinels using
183
+ identity to circumvent objects which can't be compared with equality against others
184
+ in a truth context, like with numpy arrays (#5606).
185
+ """
186
+ testdir .makepyfile (
187
+ dummy = """
188
+ class NumpyLike:
189
+ def __init__(self, value):
190
+ self.value = value
191
+ def __eq__(self, other):
192
+ raise ValueError("like numpy, cannot compare against others for truth")
193
+ FOO = NumpyLike(10)
194
+ """
195
+ )
196
+ testdir .makepyfile (
197
+ """
198
+ from unittest.mock import patch
199
+ import dummy
200
+ class Test(object):
201
+ @patch("dummy.FOO", new=dummy.NumpyLike(50))
202
+ def test_hello(self):
203
+ assert dummy.FOO.value == 50
204
+ """
205
+ )
206
+ reprec = testdir .inline_run ()
207
+ reprec .assertoutcome (passed = 1 )
208
+
181
209
def test_mock (self , testdir ):
182
210
pytest .importorskip ("mock" , "1.0.1" )
183
211
testdir .makepyfile (
You can’t perform that action at this time.
0 commit comments