title: Mocking a Celery task call in Python with patch
body: <p>Patching a Celery task call with a mocked return value returns <code>&lt;Mock name='mock().get()' ...&gt;</code> instead of the expected <code>return_value</code> defined by <code>mock_task.get.return_value = "value"</code>. However, the mocked task functions correctly within my unit test.</p>
  
  <p>Here is the unit test where I am patching my Celery task:</p>
  
  <pre><code>def test_foo(self):
  
      mock_task = Mock()
      mock_task.get = Mock(return_value={'success': True})
  
      print mock_task.get() # outputs {'success': True}
  
      with patch('app.tasks.my_task.delay', new=mock_task) as mocked_task:
          foo()  # this calls the mocked task with an argument, 'input from foo'
          mock_tasked.assert_called_with('input from foo')  # works
  </code></pre>
  
  <p>And here is the function being tested:</p>
  
  <pre><code>def foo():
      print tasks.my_task.delay  # shows a Mock object, as expected
      # now let's call get() on the mocked task:
      task_result = tasks.my_task.delay('input from foo').get()
      print task_result  # =&gt; &lt;Mock name='mock().get()' id='122741648'&gt;
      # unexpectedly, this does not return {'success': True}
      if task_result['success']:
          ...
  </code></pre>
  
  <p>The last line raises <code>TypeError: 'Mock' object has no attribute '__getitem__'</code></p>
  
  <p>Why can I call mock_task.get() from within my unit test, but calling it from <code>foo</code> returns a <code>&lt;Mock ...&gt;</code> instead of the expected return value?</p>