My code tests if the inputted email and username are the same and raises an error if they are not. I am trying to test the code and it should pass if an exception is raised but I get the exception but the test still fails. Code:
def is_valid_email(email, cognitoUsername):
if email != cognitoUsername:
print("User email invalid")
raise Exception("Username and Email address must be the same")
print("User email valid")
return True
Test:
self.assertEqual(lambda_function.is_valid_email("test@email.com", "test@email.com"), True)
self.assertRaises(Exception, lambda_function.is_valid_email("test@email.com", "test"))
Error:
email = 'test@email.com', cognitoUsername = 'test'
def is_valid_email(email, cognitoUsername):
if email != cognitoUsername:
print("User email invalid")
> raise Exception("Username and Email address must be the same")
E Exception: Username and Email address must be the same
../lambda_function.py:32: Exception
============================== 1 failed in 0.53s ===============================
Process finished with exit code 1