Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assertionerror returning empty string in python

Tags:

python

assert

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.

like image 410
tipu Avatar asked Feb 15 '11 20:02

tipu


People also ask

How do you resolve AssertionError?

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.

What causes an AssertionError in Python?

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.

How do I stop assertion errors in Python?

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.

How do I raise AssertionError in Python?

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.


1 Answers

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.

like image 129
Daniel Roseman Avatar answered Nov 09 '22 03:11

Daniel Roseman