title: Python: Mock doesn't work inside celery task
body: <p>I want to use python <code>mock</code> library for testing that my Django application sends email.</p>
  
  <p>Test code:</p>
  
  <pre><code># tests.py
  from django.test import TestCase
  
  class MyTestCase(TestCase):
  
      @mock.patch('django.core.mail.mail_managers')
      def test_canceled_wo_claiming(self, mocked_mail_managers):
          client = Client()
          client.get('/')
          print(mocked_mail_managers.called)
          mocked_mail_managers.assert_called_with('Hi, managers!', 'Message Body')
  </code></pre>
  
  <p><strong>First example - without tasks</strong></p>
  
  <pre><code># views.py
  from django.views.generic import View
  from django.core.mail import mail_managers
  
  class MyView(View):
  
      def get(self, request):
          mail_managers('Hi, managers!', 'Message Body')
          return HttpResponse('Hello!')
  </code></pre>
  
  <p><strong>Second example - with tasks</strong></p>
  
  <pre><code># views.py
  from django.views.generic import View
  from . import tasks
  
  class MyView(View):
      def get(self, request):
          tasks.notify.apply_async()
          return HttpResponse('Hello!')
  
  
  # tasks.py
  from celery import shared_task
  from django.core.mail import mail_managers
  
  @shared_task
  def notify():
      mail_managers('Hi, managers!', 'Message Body')
  </code></pre>
  
  <p>The first example works normal, second example fails, with <code>Not called</code> exception. </p>
  
  <p>My settings:</p>
  
  <pre><code># Celery
  BROKEN_URL = 'memory://'
  BROKER_BACKEND = 'memory'
  
  CELERY_ALWAYS_EAGER = True
  CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
  TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner'
  </code></pre>
  
  <p>Is it possible to perform such integrated test or the only way to solve this problem is split test into two?</p>