如何在python协同程序上进行覆盖?

如何在python协同程序上进行覆盖?,python,code-coverage,tornado,yield,coroutine,Python,Code Coverage,Tornado,Yield,Coroutine,我在Python2.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

我在Python2.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
    ...
就这样