Search code examples
pythonassert

assertionerror returning empty string in python


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.


Solution

  • 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.