Process DEFAULT values in mock side_effect that returns iterator.
Patch by Michael Ford.
This commit is contained in:
commit
8ab1e513c1
|
@ -931,6 +931,8 @@ class CallableMixin(Base):
|
|||
result = next(effect)
|
||||
if _is_exception(result):
|
||||
raise result
|
||||
if result is DEFAULT:
|
||||
result = self.return_value
|
||||
return result
|
||||
|
||||
ret_val = effect(*args, **kwargs)
|
||||
|
|
|
@ -978,6 +978,10 @@ class MockTest(unittest.TestCase):
|
|||
self.assertRaises(StopIteration, mock)
|
||||
self.assertIs(mock.side_effect, this_iter)
|
||||
|
||||
def test_side_effect_iterator_default(self):
|
||||
mock = Mock(return_value=2)
|
||||
mock.side_effect = iter([1, DEFAULT])
|
||||
self.assertEqual([mock(), mock()], [1, 2])
|
||||
|
||||
def test_assert_has_calls_any_order(self):
|
||||
mock = Mock()
|
||||
|
|
Loading…
Reference in New Issue