          with self.assertRaises(TypeError):
              Article.objects.dates()
  
      def test_dates_fails_when_given_invalid_field_argument(self):
          self.assertRaisesMessage(
              FieldError,
              "Cannot resolve keyword 'invalid_field' into field. Choices are: "
              "categories, comments, id, pub_date, pub_datetime, title",
              Article.objects.dates,
              "invalid_field",
 
</s> remove             Article.objects.dates,
            "invalid_field",
            "year",
        )
 </s> add         ):
            Article.objects.dates('invalid_field', 'year') </s> remove         self.assertRaisesMessage(
 </s> add         with self.assertRaisesMessage( </s> remove             lambda: SelfRefer.objects.filter(porcupine='fred')
        )
 </s> add         ):
            SelfRefer.objects.filter(porcupine='fred') </s> remove                 self.assertRaises(expected_exc, func)
 </s> add                 with self.assertRaises(expected_exc):
                    func() </s> remove                 self.assertRaisesMessage(expected_exc, msg, func)
 </s> add                 with self.assertRaisesMessage(expected_exc, msg):
                    func()
        with self.assertRaisesMessage(
          with self.assertRaises(TypeError):
              Article.objects.dates()
  
      def test_dates_fails_when_given_invalid_field_argument(self):
        with self.assertRaisesMessage(
              FieldError,
              "Cannot resolve keyword 'invalid_field' into field. Choices are: "
              "categories, comments, id, pub_date, pub_datetime, title",
              Article.objects.dates,
              "invalid_field",
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaisesMessage in tests.

Follow up to 253adc2b8a52982139d40c4f55b3fd446e1cb8f3. 
tests/dates/tests.py