0
我期待單元測試類的方法,使一個函數調用popen方法,並在其上執行某些操作的內部。覆蓋函數調用的方法
from os import popen
class myclass(object):
''' Generic class. '''
def do_something(self):
ret = popen("cat some_file")
# do some work with the returned value here
return modified_ret
我需要控制從popen調用中返回的內容以測試該方法。什麼是最好的方式去做?
編輯:我也有,在這個單一類POPEN使用多種方法;所以如果我可以在實例上覆蓋它,而不是整個類將會很棒。