In the Python unittest framework, is there a way to pass a unit test if an exception wasn’t raised, and fail with an AssertRaise otherwise?
In the Python unittest framework, is there a way to pass a unit test
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I understand your question correctly, you could do something like this:
…assuming that you have a corresponding test that the correct
Exceptiongets raised on invalid input, of course:However, as pointed out in the comments, you need to consider what it is that you are actually testing. It’s likely that a test like…
…is better because it tests the desired behaviour of the system and will fail if an exception is raised.