如何覆盖 python 协程?
How to do coverage on a python coroutine?
我在 python 2.7 中使用 tornado 协程并且我已经完成了这样的单元测试:
def test_my_coroutine_function(self):
# Arranges
...
# Acts
response = yield my_function()
# Asserts
...
我的函数是这样定义的:
@tornado.gen.coroutine
def my_function(self):
a = True
我的问题是 coverage.py 告诉我 "a = True" 行没有被覆盖。
要使用覆盖,我运行下面的命令行:
coverage run -m --source=./ unittest discover ./; coverage html;
感谢您的帮助。
好的,我知道如何让它工作了。
我只需要用以下内容替换我的单元测试:
def test_my_coroutine_function(self):
# Arranges
...
# Acts
future_response= yield my_function()
response = future_response.result()
# Asserts
...
就是这样。
我在 python 2.7 中使用 tornado 协程并且我已经完成了这样的单元测试:
def test_my_coroutine_function(self):
# Arranges
...
# Acts
response = yield my_function()
# Asserts
...
我的函数是这样定义的:
@tornado.gen.coroutine
def my_function(self):
a = True
我的问题是 coverage.py 告诉我 "a = True" 行没有被覆盖。
要使用覆盖,我运行下面的命令行:
coverage run -m --source=./ unittest discover ./; coverage html;
感谢您的帮助。
好的,我知道如何让它工作了。
我只需要用以下内容替换我的单元测试:
def test_my_coroutine_function(self):
# Arranges
...
# Acts
future_response= yield my_function()
response = future_response.result()
# Asserts
...
就是这样。