      def test_distinct_not_implemented_checks(self):
          # distinct + annotate not allowed
          with self.assertRaises(NotImplementedError):
              Celebrity.objects.annotate(Max('id')).distinct('id')[0]
          with self.assertRaises(NotImplementedError):
              Celebrity.objects.distinct('id').annotate(Max('id'))[0]
  
          # 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]
 
</s> remove         with self.assertRaises(NotImplementedError):
 </s> add         msg = 'aggregate() + distinct(fields) not implemented.'
        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(CommandError):
 </s> add         with self.assertRaisesMessage(CommandError, 'You must use --email with --noinput.'): </s> remove             with self.assertRaises(NotImplementedError):
 </s> add             msg = 'Bilateral transformations on nested querysets are not supported.'
            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):
        with self.assertRaisesMessage(NotImplementedError, msg):
      def test_distinct_not_implemented_checks(self):
          # distinct + annotate not allowed
          with self.assertRaises(NotImplementedError):
              Celebrity.objects.annotate(Max('id')).distinct('id')[0]
        with self.assertRaisesMessage(NotImplementedError, msg):
              Celebrity.objects.distinct('id').annotate(Max('id'))[0]
  
          # 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]
keep keep keep keep replace keep keep keep keep keep
 Used assertRaisesMessage() to test Django's error messages. 
tests/distinct_on_fields/tests.py