title: Django simpler unit test takes 10 times longer than a slightly more complex unit test
body: <p>I am working on some simple Unit Tests in <code>Django==1.11</code> and <code>python==2.7.12</code>. All of the similar tests the execution time of the test is around <code>0.0040 seconds</code>, for example the custom <code>suspend</code> action which is included with test at the bottom of the post. All of the used classes, forms, called functions are mocked in all tests. Though, the test of the <code>unsuspend</code> action consumes 10 times as much time to execute with an average of <code>0.0400 seconds</code> which I do not understand why, since it is even slightly simpler then the <code>suspend</code> action.</p>
  
  <pre><code># The custom unsuspend DRF action being tested
  @action(methods=['get'], detail=True, permission_classes=[OrganizationBasePermissions])
  def unsuspend(self, request, uuid):
      organization = self.get_object()
  
      start = datetime.datetime.now()
      mc_organization.services.organization.unsuspend(organization=organization)
      end = datetime.datetime.now()
  
      print('service call duration:', end - start)
      # ('service call duration:', datetime.timedelta(0, 0, 143))
  
      serializer = self.get_serializer(instance=organization)
      return Response(data=serializer.data, status=status.HTTP_200_OK)
  
  # The unittest of the unsuspend action above
  @mock.patch('mc_organization.api.viewsets.organization.Response')
  @mock.patch('mc_organization.api.viewsets.organization.ModelViewSet.get_serializer')
  @mock.patch('mc_organization.api.viewsets.organization.'
              'mc_organization.services.organization.unsuspend')
  @mock.patch('mc_organization.api.viewsets.organization.ModelViewSet.get_object')
  def test_viewset_unsuspend_action(self, get_object_mock, unsuspend_service_mock, get_serializer_mock,
                                    response_mock):
      get_object_mock.return_value = self.organization
      get_serializer_mock.return_value = self.serialized_organization
  
      self.viewset.unsuspend(request=self.request, uuid=self.organization.uuid)
  
      self.assertEqual(get_object_mock.call_count, 1)
      unsuspend_service_mock.assert_called_once_with(organization=self.organization)
      get_serializer_mock.assert_called_once_with(instance=self.organization)
      response_mock.assert_called_once_with(data=self.serialized_organization.data, status=status.HTTP_200_OK)
  </code></pre>
  
  <p>When printing the called methods to see if they are properly mocked, the results show
  the expected mocked values:</p>
  
  <pre><code>print('mocked get object?:', self.get_object())
  print('mocked service?:', mc_organization.services.organization.unsuspend)
  print('mocked get_serializer?:', self.get_serializer())
  print('mocked Response?:', Response())
  
  # ('mocked get object?:', &lt;MagicMock name='mock.user.organization' id='139678650884304'&gt;)
  # ('mocked service?:', &lt;MagicMock name='unsuspend' id='139678651183504'&gt;)
  # ('mocked get_serializer?:', &lt;MagicMock name='get_serializer()' id='139678650905808'&gt;)
  # ('mocked Response?:', &lt;MagicMock name='Response()' id='139678651836496'&gt;)
  </code></pre>
  
  <p>I am using <code>django-slowtests</code> to track my slowest tests, these are the results:</p>
  
  <pre><code>5 slowest tests:
  0.0427s test_viewset_unsuspend_action (mc_organization.tests.api.viewsets.organization.test_u_viewset.OrganizationViewSetUnitTestCase)
  0.0051s test_viewset_suspend_action_with_valid_request_data (mc_organization.tests.api.viewsets.organization.test_u_viewset.OrganizationViewSetUnitTestCase)
  ...
  </code></pre>
  
  <p>The suspend action test below is slightly (very slightly) more complex and takes almost 10-times less time to execute:</p>
  
  <pre><code># The custom DRF action suspend, which is more complex but takes less time to execute
  @action(methods=['post'], detail=True, permission_classes=[OrganizationBasePermissions])
  def suspend(self, request, uuid):
      organization = self.get_object()
  
      form = OrganizationSuspendForm(data=request.data, organization=organization)
  
      if not form.is_valid():
          return Response(data=form.errors, status=status.HTTP_400_BAD_REQUEST)
  
      mc_organization.services.organization.suspend(
          organization=organization,
          reason=form.cleaned_data.get('suspended_reason')
      )
      serializer = self.get_serializer(instance=organization)
  
      return Response(data=serializer.data, status=status.HTTP_200_OK)
  
  @mock.patch('mc_organization.api.viewsets.organization.Response')
  @mock.patch('mc_organization.api.viewsets.organization.'
              'mc_organization.services.organization.suspend')
  @mock.patch('mc_organization.api.viewsets.organization.ModelViewSet.get_serializer')
  @mock.patch('mc_organization.api.viewsets.organization.OrganizationSuspendForm')
  @mock.patch('mc_organization.api.viewsets.organization.ModelViewSet.get_object')
  def test_viewset_suspend_action_with_valid_request_data(self, get_object_mock, form_mock, get_serializer_mock,
                                                          suspend_service_mock, response_mock):
      get_object_mock.return_value = self.organization
      form_mock.return_value.is_valid.return_value = True
      form_mock.return_value.cleaned_data.get.return_value = "suspend reason"
      get_serializer_mock.return_value = self.serialized_organization
  
      self.viewset.suspend(request=self.request, uuid=self.organization.uuid)
  
      self.assertEqual(get_object_mock.call_count, 1)
      form_mock.assert_called_once_with(data=self.request.data, organization=self.organization)
      suspend_service_mock.assert_called_once_with(
          organization=self.organization,
          reason=form_mock.return_value.cleaned_data.get.return_value
      )
      get_serializer_mock.assert_called_once_with(instance=self.organization)
      response_mock.assert_called_once_with(data=self.serialized_organization.data, status=status.HTTP_200_OK)
  </code></pre>
  
  <p>How can it be that the <code>unsuspend</code> action unit test take almost 10 times longer than the more complex <code>suspend</code> action unittest,
  and how could I resolve this?</p>
  
  <p><strong>Minor update</strong>:
  Removing the slowest test, being the <code>unsuspend</code> unit test will make the <code>suspend</code> unit test the slowest test:</p>
  
  <pre><code>0.0539s test_viewset_unsuspend_action (mc_organization.tests.api.viewsets.organization.test_u_viewset.OrganizationViewSetUnitTestCase)
  0.0040s test_viewset_suspend_action_with_valid_request_data (mc_organization.tests.api.viewsets.organization.test_u_viewset.OrganizationViewSetUnitTestCase)
  </code></pre>
  
  <p>After removing:</p>
  
  <pre><code>0.0546s test_viewset_update_action_with_invalid_request_data (mc_organization.tests.api.viewsets.organization.test_u_viewset.OrganizationViewSetUnitTestCase)
  </code></pre>
  
  <p>What could cause this and is this expected behavior?</p>