#33348: Change API of assertFormError to take an actual form object
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                    Owner:  nobody
         Type:                       |                   Status:  assigned
  Cleanup/optimization               |
    Component:  Testing framework    |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Baptiste Mispelon):

 As an argument in favor of this change, may I present this lines from
 `tests/admin_views/tests.py:6540` [1]

 {{{#!py
 msg = "The formset 'inline_admin_formset' in context 22 does not contain
 any non-form errors."
 with self.assertRaisesMessage(AssertionError, msg):
     self.assertFormsetError(response, 'inline_admin_formset', None, None,
 ['Error'])
 }}}

 Over the years as more and more templates got involved in the rendering of
 admin views, the exact number needed to make this test pass went from 4 to
 10 to 12 to 22 (and every time, I suspect someone changed it manually to
 whichever new number the test failure asked for).

 With the change I propose, the test would look like this:
 {{{#!py
 for formset in response.context['inline_admin_formsets']:
     with self.assertRaisesMessage("The formset does not contain any non-
 form errors"):
         self.assertFormsetError(formset, None, None, ['error']
 }}}

 Though on second thought, in this case I think we can skip
 `assertFormsetError` altogether:
 {{{#!py
 for i, formset in enumerate(response.context['inline_admin_formsets']):
     with self.subTest(i=i):
         self.assertEqual(formset.non_form_errors(), [])
 }}}

 [1]
 
https://github.com/django/django/blob/8a4e5067605e608c3fcbb5ca11e0019eac8b40aa/tests/admin_views/tests.py#L6540

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33348#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.49915c6ecb2c93933457e8e06cd7110a%40djangoproject.com.

Reply via email to