mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.10.x] Replaced use of TestCase.fail() with assertRaises().
Also removed try/except/fail antipattern that hides exceptions.
Backport of c9ae09addf from master
			
			
This commit is contained in:
		| @@ -289,7 +289,7 @@ class ModelFormBaseTest(TestCase): | ||||
|                          ['name', 'slug', 'url', 'some_extra_field']) | ||||
|  | ||||
|     def test_extra_field_model_form(self): | ||||
|         try: | ||||
|         with self.assertRaisesMessage(FieldError, 'no-field'): | ||||
|             class ExtraPersonForm(forms.ModelForm): | ||||
|                 """ ModelForm with an extra field """ | ||||
|                 age = forms.IntegerField() | ||||
| @@ -297,24 +297,15 @@ class ModelFormBaseTest(TestCase): | ||||
|                 class Meta: | ||||
|                     model = Person | ||||
|                     fields = ('name', 'no-field') | ||||
|         except FieldError as e: | ||||
|             # Make sure the exception contains some reference to the | ||||
|             # field responsible for the problem. | ||||
|             self.assertIn('no-field', e.args[0]) | ||||
|         else: | ||||
|             self.fail('Invalid "no-field" field not caught') | ||||
|  | ||||
|     def test_extra_declared_field_model_form(self): | ||||
|         try: | ||||
|             class ExtraPersonForm(forms.ModelForm): | ||||
|                 """ ModelForm with an extra field """ | ||||
|                 age = forms.IntegerField() | ||||
|         class ExtraPersonForm(forms.ModelForm): | ||||
|             """ ModelForm with an extra field """ | ||||
|             age = forms.IntegerField() | ||||
|  | ||||
|                 class Meta: | ||||
|                     model = Person | ||||
|                     fields = ('name', 'age') | ||||
|         except FieldError: | ||||
|             self.fail('Declarative field raised FieldError incorrectly') | ||||
|             class Meta: | ||||
|                 model = Person | ||||
|                 fields = ('name', 'age') | ||||
|  | ||||
|     def test_extra_field_modelform_factory(self): | ||||
|         with self.assertRaises(FieldError): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user