          # However this check is done only when the query executes, so you
          # can use distinct() to remove the fields before execution.
          Celebrity.objects.distinct('id').annotate(Max('id')).distinct()[0]
          # distinct + aggregate not allowed
          with self.assertRaises(NotImplementedError):
              Celebrity.objects.distinct('id').aggregate(Max('id'))
  
      def test_distinct_on_in_ordered_subquery(self):
          qs = Staff.objects.distinct('name').order_by('name', 'id')
          qs = Staff.objects.filter(pk__in=qs).order_by('name')
 
</s> remove         with self.assertRaises(NotImplementedError):
 </s> add         with self.assertRaisesMessage(NotImplementedError, msg): </s> remove         with self.assertRaises(NotImplementedError):
 </s> add         msg = 'annotate() + distinct(fields) is not implemented.'
        with self.assertRaisesMessage(NotImplementedError, msg): </s> remove         with self.assertRaises(ValueError):
 </s> add         msg = "The annotation 'book_contact_set' conflicts with a field on the model."
        with self.assertRaisesMessage(ValueError, msg): </s> remove         with self.assertRaises(CommandError):
 </s> add         with self.assertRaisesMessage(CommandError, 'You must use --email with --noinput.'): </s> remove         with self.assertRaises(FieldError):
 </s> add         msg = "Cannot compute Avg('mean_age'): 'mean_age' is an aggregate"
        with self.assertRaisesMessage(FieldError, msg):
        msg = 'aggregate() + distinct(fields) not implemented.'
        with self.assertRaisesMessage(NotImplementedError, msg):
          # However this check is done only when the query executes, so you
          # can use distinct() to remove the fields before execution.
          Celebrity.objects.distinct('id').annotate(Max('id')).distinct()[0]
          # distinct + aggregate not allowed
        msg = 'aggregate() + distinct(fields) not implemented.'
        with self.assertRaisesMessage(NotImplementedError, msg):
              Celebrity.objects.distinct('id').aggregate(Max('id'))
  
      def test_distinct_on_in_ordered_subquery(self):
          qs = Staff.objects.distinct('name').order_by('name', 'id')
          qs = Staff.objects.filter(pk__in=qs).order_by('name')
keep keep keep keep replace keep keep keep keep keep
 Used assertRaisesMessage() to test Django's error messages. 
tests/distinct_on_fields/tests.py