[mock open]PyUnit執行單元測試時使用字符串模擬文件對象

def mock_open(data):
    from StringIO import StringIO
    stmp = StringIO(data)
    return stmp
_open = __builtins__.open
__builtins__.open = mock_open
# test case here
__builtins__.open = _open
相關文章
相關標籤/搜索