Django's custom TestCase class is a subclass of unittest.TestCase
and all of its assert functions have a msg
argument which when passed are used as the error message when an assertion fails. Also since you want the forms error to be displayed, you can get the form instance from the context and get its errors. Something like this should work:
assertEqual(response.status_code, 302, str(response.context['form'].errors))
Note forms also have form.errors.as_data()
which will show the exceptions raised during form validation, or form.errors.as_json()
any of which you might find more usable. Reference Form.errors
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…