翻译 mock.patch注释

mock.patch是一个用于替换目标对象的功能,可以作为函数、类装饰器或上下文管理器。它可以在函数体内将目标替换为新的对象,并在函数执行结束后还原。默认使用MagicMock,可以通过spec或autospec参数指定行为。它可以用于测试不实际存在的API,通过create参数创建临时属性。
摘要由CSDN通过智能技术生成
<pre name="code" class="python">
def patch(
        target, new=DEFAULT, spec=None, create=False,
        spec_set=None, autospec=None, new_callable=None, **kwargs
    ):
    """
    `patch` acts as a function decorator, class decorator or a context
    manager. Inside the body of the function or with statement, the `target`
    is patched with a `new` object. When the function/with statement exits
    the patch is undone.
    
    patch做为函数装饰器,类装饰器或者一个context管理器,在函数实现内部,
    target被patched成另外一个object(new所指向得),当函数退出时,patch同时也失效。

    If `new` is omitted, then the target is replaced with a
    `MagicMock`. If `patch` is used as a decorator and `new` is
    omitted, the created mock is passed in as an extra argument to the
    decorated 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值