<br><br><div class="gmail_quote">On Mon, Jun 6, 2011 at 8:25 PM, John Anderson <span dir="ltr">&lt;<a href="mailto:sontek@gmail.com">sontek@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I wrote this script that monitors memory usage of processes and kills them if they get too high.  I&#39;m having a hard time figuring out how to test something like this.</blockquote><div><br>I&#39;ve had similar issues when testing deamons... it is hard if what you are trying to test is double forking! <br>

</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><br></div><div>Would you just mock out the process list and test that if you pass it a process list it calls send_signal?  Thats what i&#39;m thinking about doing but would like to hear other peoples opinions!</div>

</blockquote><div><br>There are a couple of things I would do, but most definitely I would start by breaking your script in such a way that the actual call to the processes is a <br>simple/small function (maybe a method).<br>

<br>If you get to that point, then you get to test all the other parts easily, without worrying about the process list.<br><br>Having said that, you still need to test the *actual* work that needs to be done to get information about the process. In that case I would mock the processes but I would keep a couple of separate tests that do not actually use mock at all but deal with the *real* thing.<br>

<br>You could create real processes with certain memory parameters and then assert that your script is killing them appropriately. That way you end up with<br>the best of both worlds... you are testing all the &quot;unit&quot; parts of your script, but as a safety net, you are also doing some testing with actual processes. <br>

<br>I would run the unit tests that use mocking all the time and would save myself to run the non-mocking ones at other moments (e.g. when getting close to a new library version or release).<br><br>  <br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


<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></div><br>