          except FieldError:
              self.fail('Declarative field raised FieldError incorrectly')
  
      def test_extra_field_modelform_factory(self):
          self.assertRaises(FieldError, modelform_factory,
                            Person, fields=['no-field', 'name'])
  
      def test_replace_field(self):
          class ReplaceField(forms.ModelForm):
              url = forms.BooleanField()
  
 
</s> remove         self.assertRaises(TypeError, modelform_factory, Person, fields="__all__",
                          formfield_callback='not a function or callable')
 </s> add         with self.assertRaises(TypeError):
            modelform_factory(Person, fields="__all__", formfield_callback='not a function or callable') </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(SuspiciousOperation,
                              HttpResponseRedirect, url)
            self.assertRaises(SuspiciousOperation,
                              HttpResponsePermanentRedirect, url)
 </s> add             with self.assertRaises(SuspiciousOperation):
                HttpResponseRedirect(url)
            with self.assertRaises(SuspiciousOperation):
                HttpResponsePermanentRedirect(url) </s> remove         self.assertRaises(FieldError, Poll.objects.get,
            choice__name__exact="This is the answer")
 </s> add         with self.assertRaises(FieldError):
            Poll.objects.get(choice__name__exact="This is the answer") </s> remove         self.assertRaises(TypeError, build_no_cbc)
 </s> add         with self.assertRaises(TypeError):
            build_no_cbc()
        with self.assertRaises(FieldError):
            modelform_factory(Person, fields=['no-field', 'name'])
          except FieldError:
              self.fail('Declarative field raised FieldError incorrectly')
  
      def test_extra_field_modelform_factory(self):
        with self.assertRaises(FieldError):
            modelform_factory(Person, fields=['no-field', 'name'])
        with self.assertRaises(FieldError):
            modelform_factory(Person, fields=['no-field', 'name'])
  
      def test_replace_field(self):
          class ReplaceField(forms.ModelForm):
              url = forms.BooleanField()
  
keep keep keep keep replace replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/model_forms/tests.py