<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&#39;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(&#39;__builtin__.open&#39;, my_mock):</div>
<div>
            manager = my_mock.return_value.__enter__.return_value</div><div>            manager.read.return_value = StringIO(&quot;my,example,input&quot;)</div><div>            with open(&#39;x&#39;) as f:</div><div>                reader = csv.reader(f)</div>
<div>                for row in reader:</div>                    print row<br><br></div>Flavio<br></div>