from mock import patch, mock_open
with open('ref.dat') as f:
ref_output = f.read()
with open('input.dat') as f:
input = f.read()
with patch('__builtin__.open', mock_open(read_data=input)) as m:
foo()
m.assert_called_with('output.dat', 'w')
m().write.assert_called_once_with(ref_output)
我找到了以下解决方案:
相关问题 更多 >
编程相关推荐