例如,我在文件中写了一些数据,然后尝试阅读它们:
mocked_open = mock_open()
with patch('__builtin__.open', mocked_open, create=True):
with open('file', 'w') as f:
f.write('text')
with open('file', 'r') as f:
res = f.read()
但在此之后,res
为空。如何获取此文件的书面数据?