<div dir="ltr">Assuming you are doing a unit test (aka microtest):<br><br>One easy way to avoid file system dependencies is to separate out a function that opens the file you specify.<div>It becomes a very trivial function, of course.</div><div><br>In the test, you stub that function to return a file-like object of the fake content you need in order for the test to work. <br>This works just fine whether reading or writing.<div><br></div><div>Of course, if you want to fake a higher level, you can split out a function that opens the file and parses the data -- then mock that function out. <br><br>If nothing else is easy/quick/handy, you can always extract and mock your way out of (nearly) any situation.<div><br></div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 9, 2017 at 8:34 AM Gregory Salvan <<a href="mailto:apieum@gmail.com">apieum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I'm not advocating against functionnal tests in my answer, but if you want my opinion about them it's best explained here: <a href="http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam" target="_blank">http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam</a><br><br></div>Then I've answered for TDD and BDD and not for real live system, the purpose is different. By the way if you have cases where it's relevant to test open() in real live system, I'm curious.<br></div>Once you've tested open() is called correctly (by injecting a mock of open()) what's the point to test if it works in a real live system otherwise testing if open() implementation works correctly?<br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-09 14:31 GMT+02:00 Matt Wheeler <span dir="ltr"><<a href="mailto:m@funkyhat.org" target="_blank">m@funkyhat.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span><div class="gmail_quote"><div dir="ltr">On Tue, 9 May 2017, 11:50 Gregory Salvan, <<a href="mailto:apieum@gmail.com" target="_blank">apieum@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's to generic to have complex examples, but you really can test everything without writing data in files, and it's not really relevant to test if data are really written as it's the same as testing if there's no errors in python "open" implementation. I think we can trust python developpers for that ;)</div></blockquote></div><div><br></div></span><div>No, it's not just testing that open() works correctly, it's also testing that it's being called correctly in a real* live system. You seem to be advocating against functional tests as a concept?</div><div><br></div><div>*certainly more real than a system involving mocking open() in a unit test.</div><span class="m_-2361777801764051398HOEnZb"><font color="#888888"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></font></span></div><span class="m_-2361777801764051398HOEnZb"><font color="#888888"><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">--<br>
Matt Wheeler<br>
<a href="http://funkyh.at" target="_blank">http://funkyh.at</a></p>
</div></div>
</font></span></blockquote></div><br></div>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div>