简体   繁体   中英

I have a python file with multiple exception for each block , I need to utest for the same . Is there any approach to cover all exceptions at one go?

Sample python file for which utest is to be written:

try:

    code

except Exception as e:
    print



try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print
    

try:

    code

except Exception as e:

    print

I think you are looking for this:

try:
    foo()
except (SomeException, OtherException, AnotherException) as exp:
    ...

https://docs.python.org/3/tutorial/errors.html#handling-exceptions

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM