问题
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'crow@crow.com',
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?
回答1:
Use form.errors:
errors
A dict containing a list of errors for each field. Empty if the form hasn’t been validated, or there were no errors.
回答2:
You can print the errors by adding the following: print form.errors.items().
来源:https://stackoverflow.com/questions/24578039/how-to-view-wtforms-validation-errors