Python:如何测试处理异常的路径?

时间:2016-11-28 16:23:26

标签: python mocking python-mock

鉴于此代码:

def main(b):
    try:
        a = 2 / b
        return "Hello World"
    except Exception:
        return "Exception"

如何使用修补测试处理异常的路径? 是否可以将a = 2 / b作为修补的有效目标?

类似的问题:

How to use Python Mock to raise an exception - but with Errno set to a given value

Mocking - How do I raise exception on the caller?

Mocking a function to raise an Exception to test an except block

0 个答案:

没有答案