我想测试一个huey任务,并且需要打补丁requests.get
。运行测试如何在huey任务中进行模拟/猴子修补?
# huey_tasks.py
from huey import RedisHuey
huey = RedisHuey()
@huey.task()
def function():
import requests
print(requests.get('http://www.google.com'))
文件:
import huey_tasks
@patch('requests.get')
def call_patched(fake_get):
fake_get.return_value = '1'
huey_tasks.function()
启动huey_consumer:huey_tasks.huey -w 10 -l logs/huey.log
运行测试,但是打补丁并没有任何影响。
[2016-01-24 17:01:12,053] INFO:requests.packages.urllib3.connectionpool:Worker-1:Starting new HTTP connection (1): www.google.com
[2016-01-24 17:01:12,562] INFO:requests.packages.urllib3.connectionpool:Worker-1:Starting new HTTP connection (1): www.google.com.sg
<Response[200]>
如果我删除@huey.task()
装饰,修补工程和1
被打印出来。
那么应该怎么测试休伊任务?毕竟,我无法每次删除装饰器,都必须是更好的方法。