I am writing some basic tests and have a test failing.
def test_new_user_registration(self):
  self.client.get('/user/register')
  form = RegistrationForm(
    email=u'[email protected]',
    first_name=u'Alex',
    last_name=u'Frazer',
    username=u'crow',
    password=u'fake_password',
    confirm_password=u'fake_password'
  )
  self.assertTrue(form.validate())
The assertion error is failing on form.validate(), but how can I view what the validation errors are?
Flask WTForms is a library that makes form handling easy and structured. It also ensures the effective handling of form rendering, validation, and security. To build forms with this approach, you start by creating a new file in our app directory and name it forms.py. This file will contain all the application forms.
A validation error occurs when you have validation/response checking turned on for one of the questions and the respondent fails to answer the question correctly (for numeric formatting , required response).
Use form.errors:
errorsA dict containing a list of errors for each field. Empty if the form hasn’t been validated, or there were no errors.
You can print the errors by adding the following: print form.errors.items().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With