          test_gmbh = Company.objects.get(name="Test GmbH")
  
          def test():
              test_gmbh.point_of_contact = F("ceo")
          self.assertRaises(ValueError, test)
  
          test_gmbh.point_of_contact = test_gmbh.ceo
          test_gmbh.save()
          test_gmbh.name = F("ceo__last_name")
          self.assertRaises(FieldError, test_gmbh.save)
 
</s> remove         self.assertRaises(FieldError, test_gmbh.save)
 </s> add         with self.assertRaises(FieldError):
            test_gmbh.save() </s> remove         self.assertRaises(FieldError, list, qs)
        self.assertRaises(FieldError, list, qs)
 </s> add         with self.assertRaises(FieldError):
            list(qs)
        with self.assertRaises(FieldError):
            list(qs) </s> remove         self.assertRaises(FieldError, modelform_factory,
                          Person, fields=['no-field', 'name'])
 </s> add         with self.assertRaises(FieldError):
            modelform_factory(Person, fields=['no-field', 'name']) </s> remove         self.assertRaises(ValueError, indexfcn, ul, 40)
        self.assertRaises(ValueError, removefcn, ul, 40)
 </s> add         with self.assertRaises(ValueError):
            indexfcn(ul, 40)
        with self.assertRaises(ValueError):
            removefcn(ul, 40) </s> remove         self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta})
 </s> add         with self.assertRaises(ValueError):
            ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta})
        with self.assertRaises(ValueError):
            test()
          test_gmbh = Company.objects.get(name="Test GmbH")
  
          def test():
              test_gmbh.point_of_contact = F("ceo")
        with self.assertRaises(ValueError):
            test()
  
          test_gmbh.point_of_contact = test_gmbh.ceo
          test_gmbh.save()
          test_gmbh.name = F("ceo__last_name")
          self.assertRaises(FieldError, test_gmbh.save)
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/expressions/tests.py