  class SkippingTestCase(SimpleTestCase):
      def _assert_skipping(self, func, expected_exc, msg=None):
          try:
              if msg is not None:
                  self.assertRaisesMessage(expected_exc, msg, func)
              else:
                  self.assertRaises(expected_exc, func)
          except unittest.SkipTest:
              self.fail('%s should not result in a skipped test.' % func.__name__)
  
 
</s> remove                 self.assertRaises(expected_exc, func)
 </s> add                 with self.assertRaises(expected_exc):
                    func() </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.assertRaisesMessage(
 </s> add         with self.assertRaisesMessage( </s> remove             Article.objects.dates,
            "invalid_field",
            "year",
        )
 </s> add         ):
            Article.objects.dates('invalid_field', 'year')
                with self.assertRaisesMessage(expected_exc, msg):
                    func()
  class SkippingTestCase(SimpleTestCase):
      def _assert_skipping(self, func, expected_exc, msg=None):
          try:
              if msg is not None:
                with self.assertRaisesMessage(expected_exc, msg):
                    func()
              else:
                  self.assertRaises(expected_exc, func)
          except unittest.SkipTest:
              self.fail('%s should not result in a skipped test.' % func.__name__)
  
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/test_utils/tests.py