Kaydet (Commit) 8ab1e513 authored tarafından Andrew Svetlov's avatar Andrew Svetlov

Process DEFAULT values in mock side_effect that returns iterator.

Patch by Michael Ford.
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment