[Django]-Check form errors in Django testing

3👍

Here is one way you can test it. Note that you need to call the is_valid function:

self.assertFalse(form.is_valid())
self.assertEqual(form.errors['password'][0], 'It is invalid')

2👍

first you need to call is_valid method and then chceck if errors list has specific error like:

self.assertFalse(form.is_valid())
self.assertIn('password', form.errors.keys())
self.assertIn('It is invalid', form.errors['password'])
👤kuter

Leave a comment