繁体   English   中英

我有一个 python 文件,每个块都有多个异常,我需要对相同的 . 有没有办法一次性覆盖所有异常?

[英]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?

要为其编写 utest 的示例 python 文件:

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

我想你正在寻找这个:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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