<div dir="ltr"><div>Hi,<br><br>The only way to print the rows in the code below is if I use f.read() as input to csv.reader().<br>I really don't know how to test my function as I just pass the file handle to the csv.reader().<br>
Do you know the reason? How can I sort it out?<br><br><div> def test_parse_csv(self):</div><div> my_mock = mock.MagicMock(spec=file)</div><div> with mock.patch('__builtin__.open', my_mock):</div>
<div>
manager = my_mock.return_value.__enter__.return_value</div><div> manager.read.return_value = StringIO("my,example,input")</div><div> with open('x') as f:</div><div> reader = csv.reader(f)</div>
<div> for row in reader:</div> print row<br><br></div>Flavio<br></div>