<div class="markdown-here-wrapper" id="markdown-here-wrapper-985831" style><p style="margin:1.2em 0px!important">Hi Flavio,</p>
<p style="margin:1.2em 0px!important">Exactly what function are you trying to test? I assume it is the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline">with open(...)</code> block, but that&#39;s not currently in a different function. I think I could better understand your problem if you posted your test code and your function under test.</p>


<p style="margin:1.2em 0px!important">Thanks,</p>
<p style="margin:1.2em 0px!important">On Mon, Jul 8, 2013 at 3:36 AM, Flavio Oliveira &lt;<a href="mailto:flavyobr@gmail.com" target="_blank">flavyobr@gmail.com</a>&gt; wrote:</p>
<p style="margin:1.2em 0px!important"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888">Flavio<br></font></span></div>
<br>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote><p></p></div><p style="margin:1.2em 0px!important"></p>
</div><div>-- <br>Sean Fisk<br>
</div>