Custom Error Messages In Python
So I'm practicing some unit test and I have a question about error messages. I'm trying to create a custom error message that will display when the test fails. Here is a basic Hell
Solution 1:
What you could do is to catch the AssertionError by wrapping the assertEqual in a try except statement and then print the error:
try:
self.assertEqual("Hello World", hello_world,"This is a custom error")
except AssertionErroras e:
print(e)
There is however a downside when catching the AssertionError: the unittest module can no longer count the errors. (Stacktraces are not beautiful but they server the purpose of exactly pointing you to the point in the stack where the error occured.)
Post a Comment for "Custom Error Messages In Python"