我想用pytest测试async_who
函数。你知道吗
如何测试调用回调且返回值为'Bob'
import threading
def async_who(callback):
t = threading.Thread(target=_who, args=(callback,))
t.start()
def _who(callback):
return callback('Bob')
def callback(name):
print(name)
return name
async_who(callback)
因为async_who
没有返回值。我不能这么做
def test_async_who():
res = async_who(callback)
assert res == 'Bob'
来自多处理模块的ThreadPool或ThreadPoolExecutor(对于python版本>;=3.2) 是获取线程返回值的方法。你知道吗
与并发.futures.ThreadPoolExecutor
与多处理池线程池
相关问题 更多 >
编程相关推荐