2016-05-13 40 views
0

我寫了一個模塊,其中有幾個函數以及他們的doctests,我想運行這些測試的函數名稱相同,但是由其他人編寫。使用不同的函數運行doctests

的文檔提供了下面的代碼片段檢索所有測試中mymodulesomefunction,然後以通常的方式運行它們(如跑步doctest.testmod()):

TESTS = doctest.DocTestFinder().find(mymodule.somefunction) 
DTR = doctest.DocTestRunner(verbose=True) 
for test in TESTS: 
    print (test.name, '->', DTR.run(test)) 

但我不知道在哪裏何去何從代之以在theirmodule.somefunction上運行這些測試。我試圖將filename字段從mymodule更改爲theirmoduleExample對象爲每個測試,但無濟於事。有誰知道如何做到這一點?

回答

0

這可能不是最完美的解決方案,而只是複製我的文檔字符串其功能在我的腳本工作:

theirmodule.somefunction.__doc__ = mymodule.somefunction.__doc__ 

然後,我只需要在我的問題上theirmodule.somefunction運行片段。

相關問題