I am using python unittest and trying to catch the exceptions. I have tried with self.fail but in that case, once there is an exception, it is a failure and it stops running the rest of the code
What can I try so even if one case fails, it still executes the rest of the cases ?
I am trying to avoid printing the exceeptions.
Code currently using:
if 'Anonymous' in elem_welcome.text:
pass
else:
self.fail('Test Failed: Logout Failed'))
Use the try and except block and name the said 'error' on the except block Eg Error is 'NameError'
try:
#cases
except NameError:
#other cases
You can read more here Handling Exceptions
You can make every test to be a function and call it from the main block. This way each one will get executed and the failed once will return the fail reason to be filed by main block.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.