2017-01-09 30 views
0

我使用龍捲風協同程序在python 2.7和我做單元測試,像這樣的:如何對python協同程序進行覆蓋?

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; 

謝謝您的幫助。

回答

0

好吧我想出瞭如何使它的工作。

我只是具有以下取代我的單元測試:

def test_my_coroutine_function(self): 
    # Arranges 
    ... 

    # Acts 
    future_response= yield my_function() 
    response = future_response.result() 

    # Asserts 
    ... 

就是這樣。