I am doing this:
try: self.failUnless(sel.is_text_present("F!")) #sel.is_text_present("F!") is false
except AssertionError, e:
print("x"+e+"y")
sys.exit()
it is printing nothing except xy. no class name or anything else. what does the error in AssertionError normally contain?
edit: apparently the user provides its own message. selenium generated many of these:
except AssertionError, e: self.verificationErrors.append(str(e))
without sending in a message at all, so it appends a bunch of empty strings to verificationErrors.
In order to handle the assertion error, we need to declare the assertion statement in the try block and catch the assertion error in the catch block.
The assert StatementIf the expression is false, Python raises an AssertionError exception. If the assertion fails, Python uses ArgumentExpression as the argument for the AssertionError.
Steps to avoid Assertion Error in Python By disabling the assert statements in the process, the statements following the assert statements will also be not executed. We can make use of the environment variable also to set a flag that disables also the assert statements.
Python - Assert Statement In Python, the assert statement is used to continue the execute if the given condition evaluates to True. If the assert condition evaluates to False, then it raises the AssertionError exception with the specified error message.
Don't catch the errors from assertions. All the assertions in the unittest module take a final parameter, msg
, which is the message to be raised if the assertion fails. Put your debugging there if necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With