              Article._meta.get_latest_by = 'pub_date'
  
      def test_earliest(self):
          # Because no Articles exist yet, earliest() raises ArticleDoesNotExist.
          self.assertRaises(Article.DoesNotExist, Article.objects.earliest)
  
          a1 = Article.objects.create(
              headline="Article 1", pub_date=datetime(2005, 7, 26),
              expire_date=datetime(2005, 9, 1)
          )
 
</s> remove         self.assertRaises(Article.DoesNotExist, Article.objects.latest)
 </s> add         with self.assertRaises(Article.DoesNotExist):
            Article.objects.latest() </s> remove         self.assertRaises(Http404, get_object_or_404, Article, title="Foo")
 </s> add         with self.assertRaises(Http404):
            get_object_or_404(Article, title="Foo") </s> remove         self.assertRaises(ContentNotRenderedError, lambda: response.content)
 </s> add         with self.assertRaises(ContentNotRenderedError):
            response.content </s> remove         self.assertRaises(FieldError, test_gmbh.save)
 </s> add         with self.assertRaises(FieldError):
            test_gmbh.save() </s> remove         self.assertRaises(
            Book.DoesNotExist,
            Book.objects.get,
            title="Dive into Python"
        )
        self.assertRaises(
            Book.DoesNotExist,
            Book.objects.using('default').get,
            title="Dive into Python"
        )
 </s> add         with self.assertRaises(Book.DoesNotExist):
            Book.objects.get(title="Dive into Python")
        with self.assertRaises(Book.DoesNotExist):
            Book.objects.using('default').get(title="Dive into Python")
        with self.assertRaises(Article.DoesNotExist):
            Article.objects.earliest()
              Article._meta.get_latest_by = 'pub_date'
  
      def test_earliest(self):
          # Because no Articles exist yet, earliest() raises ArticleDoesNotExist.
        with self.assertRaises(Article.DoesNotExist):
            Article.objects.earliest()
  
          a1 = Article.objects.create(
              headline="Article 1", pub_date=datetime(2005, 7, 26),
              expire_date=datetime(2005, 9, 1)
          )
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/get_earliest_or_latest/tests.py