簡體   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