          """
          def check():
              # We know that we've broken the __iter__ method, so the queryset
              # should always raise an exception.
              self.assertRaises(IndexError, lambda: IndexErrorArticle.objects.all()[0])
              self.assertRaises(IndexError, IndexErrorArticle.objects.all().first)
              self.assertRaises(IndexError, IndexErrorArticle.objects.all().last)
  
          check()
  
          # And it does not matter if there are any records in the DB.
          IndexErrorArticle.objects.create(
 
</s> remove             self.assertRaises(IndexError, poly.__getitem__, len(poly))
            self.assertRaises(IndexError, poly.__setitem__, len(poly), False)
            self.assertRaises(IndexError, poly.__getitem__, -1 * len(poly) - 1)
 </s> add             with self.assertRaises(IndexError):
                poly.__getitem__(len(poly))
            with self.assertRaises(IndexError):
                poly.__setitem__(len(poly), False)
            with self.assertRaises(IndexError):
                poly.__getitem__(-1 * len(poly) - 1) </s> remove         self.assertRaises(ValueError, str, qs.query)
 </s> add         with self.assertRaises(ValueError):
            str(qs.query) </s> remove         self.assertRaises(
            ItalianRestaurant.DoesNotExist,
            lambda: Place.objects.get(name="Demon Dogs").restaurant.italianrestaurant
        )
 </s> add         with self.assertRaises(ItalianRestaurant.DoesNotExist):
            Place.objects.get(name="Demon Dogs").restaurant.italianrestaurant </s> remove         self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
 </s> add         with self.assertRaises(ValueError):
            Author.objects.annotate(friends=Count('friends')) </s> remove             self.assertRaises(IndexError, setfcn, ul, i)  # 'set index %d' % i)
            self.assertRaises(IndexError, getfcn, ul, i)  # 'get index %d' % i)
            self.assertRaises(IndexError, delfcn, ul, i)  # 'del index %d' % i)
 </s> add             with self.assertRaises(IndexError):  # 'set index %d' % i)
                setfcn(ul, i)
            with self.assertRaises(IndexError):  # 'get index %d' % i)
                getfcn(ul, i)
            with self.assertRaises(IndexError):  # 'del index %d' % i)
                delfcn(ul, i)
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all()[0]
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().first()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().last()
          """
          def check():
              # We know that we've broken the __iter__ method, so the queryset
              # should always raise an exception.
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all()[0]
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().first()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().last()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all()[0]
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().first()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().last()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all()[0]
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().first()
            with self.assertRaises(IndexError):
                IndexErrorArticle.objects.all().last()
  
          check()
  
          # And it does not matter if there are any records in the DB.
          IndexErrorArticle.objects.create(
keep keep keep keep replace replace replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/get_earliest_or_latest/tests.py