title: How to mock a queryset for use in a for loop in python/Mock
body: <p>I am writing some unit tests and want to use Mock.</p>
  
  <p>Given the following code:</p>
  
  <pre><code># the 'real' query set is a Django database model
  # qs = SomeDjangoModel.objects.filter(name='some_name')
  qs = mock.Mock()
  qs.filter.return_value = qs
  item = mock.Mock()
  item.do_work.return_value = "Some text"
  qs.iter.return_value = iter([item])
  # below is the code I want to test..
  qs = qs.filter(name='some name')
  qs = qs.filter(valid_from__lte=Timezone.now())
  for obj in qs:
      obj.do_work()
  </code></pre>
  
  <p>when run, I get </p>
  
  <blockquote>
    <p>TypeError: 'Mock' object is not iterable</p>
  </blockquote>
  
  <p>I have tried patching</p>
  
  <pre><code>@mock.patch('__builtin__.iter')
  </code></pre>
  
  <p>but I just can't seem to get it to work.
  I haven't succeeded in figuring out what really goes on when the query set "used" by the for-loop.</p>
  
  <p>Help is greatly appreciated!</p>
  
  <p>[edited with further added example code, after first solution proposal]</p>