Assertionerror returns empty string in python

I'm doing it:

try: self.failUnless(sel.is_text_present("F!")) #sel.is_text_present("F!") is false except AssertionError, e: print("x"+e+"y") sys.exit() 

prints nothing but xy. no class name or anything else. What usually contains an error in AssertionError?

edit: obviously, the user provides his own message. selenium generated many of them:

 except AssertionError, e: self.verificationErrors.append(str(e)) 

without sending a message at all, so it adds a bunch of blank lines to the Errors check.

+4
source share
3 answers

Do not catch errors from statements. All statements in unittest take the final msg parameter, which is the message that should be raised if the statement fails. Put your debugging in there, if necessary.

+4
source

The standard assert statement does not put anything in the AssertionError , it has a traceback value. There is an option assert expr, msg , which sets the error message if you use unittest, then the second argument assertTrue ( failUnless deprecated) will do this.

+4
source

It looks like you want to use your statements as debug statements in case of failure. This should help...

 import traceback try: assert 1 == 2 except AssertionError: traceback.print_exc() 

Fingerprints:

 Traceback (most recent call last): File "./foo.py", line 4, in <module> assert 1 == 2 
+1
source

Source: https://habr.com/ru/post/1339895/


All Articles