  class LookupTransformCallOrderTests(TestCase):
      def test_call_order(self):
          with register_lookup(models.DateField, TrackCallsYearTransform):
              # junk lookup - tries lookup, then transform, then fails
              with self.assertRaises(FieldError):
                  Author.objects.filter(birthdate__testyear__junk=2012)
              self.assertEqual(TrackCallsYearTransform.call_order,
                               ['lookup', 'transform'])
              TrackCallsYearTransform.call_order = []
              # junk transform - tries transform only, then fails
 
</s> remove             with self.assertRaises(FieldError):
 </s> add             with self.assertRaisesMessage(FieldError, msg): </s> remove         with self.assertRaises(TypeError):
 </s> add         msg = 'Model instances without primary key value are unhashable'
        with self.assertRaisesMessage(TypeError, msg): </s> remove         with self.assertRaises(FieldError):
 </s> add         msg = "Unsupported lookup 'blahblah' for CharField or join on the field not permitted."
        with self.assertRaisesMessage(FieldError, msg): </s> remove         with self.assertRaises(FieldError):
 </s> add         msg = "Cannot compute Avg('mean_age'): 'mean_age' is an aggregate"
        with self.assertRaisesMessage(FieldError, msg): </s> remove         with self.assertRaises(ValueError):
 </s> add         msg = "The annotation 'age' conflicts with a field on the model."
        with self.assertRaisesMessage(ValueError, msg):
            msg = "Unsupported lookup 'junk' for IntegerField or join on the field not permitted."
            with self.assertRaisesMessage(FieldError, msg):
  class LookupTransformCallOrderTests(TestCase):
      def test_call_order(self):
          with register_lookup(models.DateField, TrackCallsYearTransform):
              # junk lookup - tries lookup, then transform, then fails
            msg = "Unsupported lookup 'junk' for IntegerField or join on the field not permitted."
            with self.assertRaisesMessage(FieldError, msg):
                  Author.objects.filter(birthdate__testyear__junk=2012)
              self.assertEqual(TrackCallsYearTransform.call_order,
                               ['lookup', 'transform'])
              TrackCallsYearTransform.call_order = []
              # junk transform - tries transform only, then fails
keep keep keep keep replace keep keep keep keep keep
 Used assertRaisesMessage() to test Django's error messages. 
tests/custom_lookups/tests.py