title: How can I mock a class method of a celery Task
body: <p>Using python 2.7, celery 3.0.24 and mock 1.0.1. I have this:</p>
  
  <pre><code>class FancyTask(celery.Task):
      @classmethod
      def helper_method1(cls, name):
          """do some remote request depending on name"""
          return 'foo' + name + 'bar'
  
      def __call__(self, *args, **kwargs):
          funcname = self.name.split()[-1]
          bigname = self.helper_method1(funcname)
          return bigname
  
  
  @celery.task(base=FancyTask)
  def task1(*args, **kwargs):
      pass
  
  @celery.task(base=FancyTask)
  def task2(*args, **kwargs):
      pass
  </code></pre>
  
  <p>how can I patch <code>helper_method1</code> while testing either task?</p>
  
  <p>I've tried something like:</p>
  
  <pre><code> import mock
   from mymodule import tasks
  
   class TestTasks(unittest.TestCase):
       def test_task1(self):
           task = tasks.task1
           task.helper_method1 = mock.MagickMock(return_value='42')
           res = task.delay('blah')
           task.helper_method1.assert_called_with('blah')
  </code></pre>
  
  <p>and the test is failing. The original function is the one being called. And no, <a href="https://stackoverflow.com/q/9728748/253049">this question</a> didn't help me.</p>