在
retry您使用的装饰是建立在顶部
decorator.decorator实用的装饰,如果未安装包一个简单的回退。
结果具有一个
__wrapped__属性,可让您访问原始功能:
orig = _sftp_command_with_retries.__wrapped__
如果
decorator未安装, 并且 您使用的是3.2之前的Python版本,则该属性将不存在;您必须手动进入装饰器闭合:
orig = _sftp_command_with_retries.__closure__[1].cell_contents
(索引0处的闭包是
retry_decorator在调用
retry()自身时产生的)。
需要注意的是
decorator被列为依赖
retry包的元数据,如果你安装它
pip的
decorator包会被自动安装。
您可以使用
try...except:
try: orig = _sftp_command_with_retries.__wrapped__except AttributeError: # decorator.decorator not available and not Python 3.2 or newer. orig = _sftp_command_with_retries.__closure__[1].cell_contents
请注意,您 始终
可以
time.sleep()使用模拟补丁。装饰器代码将使用该模拟程序,因为它引用了模块源代码中的“全局”
time模块。
或者,您可以修补
retry.api.__retry_internal:
import retry.apidef dontretry(f, *args, **kw): return f()with mock.patch.object(retry.api, '__retry_internal', dontretry): # use your decorated method
这会将执行实际重试的功能临时替换为直接调用原始功能的功能。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)