Python 2.7 Python单元测试模拟,无法修补';正在“\uuuu init\uuuuuu.py”中导入`

Python 2.7 Python单元测试模拟,无法修补';正在“\uuuu init\uuuuuu.py”中导入`,python-2.7,unit-testing,mocking,Python 2.7,Unit Testing,Mocking,我在\uuuu init\uuuu.py文件中有以下代码 from time import sleep from functools import wraps def multi_try(func): @wraps(func) def inner(*args, **kwargs): count = 0 while count < 5: resp = func(*args, **kwargs)

我在\uuuu init\uuuu.py文件中有以下代码

from time import sleep
from functools import wraps

def multi_try(func):
    @wraps(func)
    def inner(*args, **kwargs):
        count = 0
        while count < 5:
            resp = func(*args, **kwargs)
            if resp.status_code in [200, 201]:
                return resp
            sleep(1)
            count += 1
    return inner
我也试过这个,

将补丁(“dir.\uuu init\uuuu.time”)作为tm:

将补丁(“dir.utils.time”)作为tm:

这导致了

AttributeError:没有“time”属性

我所要做的就是

with patch("dir.sleep" ) as tm:
而不是

with patch("time.sleep") as tm:
我所要做的就是

with patch("dir.sleep" ) as tm:
而不是

with patch("time.sleep") as tm:

看起来你相处得很好