The class:
class ABC(object):
def __init__(self, files):
self.store = []
self.parse_files(files)
def parse_files(files):
for filename in files:
with open(filename, newline="") as f:
self.store.append(f.read())
The test:
from unittest.mock import Mock, mock_open, patch
class TestABC:
result1 = 'string1'
result2 = 'string2'
result = Mock()
result.side_effect = [result1, result2]
@patch("builtins.open", new_callable=mock_open, read_data=result())
def test_parse_files(self, a):
item = ABC(['foo', 'bar'])
assert item.store == ['string1', 'string2']
But item.store == ['string1', 'string1']
I thought the open would return result1 and result2 since result() is iter?