我正在尋找一種方式來執行類似於下面的patch.specialmultiple, 我想補丁的位置,說在多個文件中使用相同的Mock對象實例的打開方法。也所以作爲裝飾的使用時,只有傳遞給裝飾功能如何蟒蛇模擬打開多個文件中的方法
模擬對象有一種用模擬
file1.py
---------
def hello():
open('test.data').read()
file2.py
--------
def world():
open('test2.data').read()
file3.py
--------
mopen = mock.MagicMock(create=True)
@patch.specialmultiple(['file1.open', 'file2.open'], new=mopen)
def test_case1(mopen):
open.side_effect = [OSError('not found'), OSError('Noy found')]