<div dir="ltr"><div><div>&gt; More specifically, unittest is great for unit testing: isolating a small<br>
unit of code and testing whether it gives expected outputs for given<br>
inputs.<br><br>Did you mean unittest as in unittest module? It was probably a Python port of the Java&#39;s Junit, IRRC. <br><br>I don&#39;t think there is anything to prevent someone to use the module to do functional testing. Unittest module is really just a set of commands such as assertEqual and what not. It is so bare metal that i don&#39;t think it was designed to be just unit testing. <br>
<br>&gt; I manage several hundred systems and I am currently using Nagios but 
instead I was wondering if unittest would be OK for something like this.<br><br></div>For system behavior testing, you need to be very specific what you want to test. Have you ever heard of Puppet, Chef, Ansible or Salt-stack? They are known as configuration management tool. The reason people use configuration management system is because they want to ensure systems are continuously configured at the state you want they to be in. Take Ansible for example, I can do this:<br>
<br></div><div>- hosts: proxy<br></div><div>  sudo: True<br></div><div>  tasks:<br></div><div>      - name: Ensure Nginx is installed<br></div><div>        apt: pkg=nginx state=present <br></div><div>      - name: Configure nginx.conf<br>
</div><div>        template: src=templates/nginx.proxy.conf.j2   dest=/etc/nginx/nginx.conf<br><br></div><div>and in nginx.proxy.conf.j2 you might have a template like this<br></div><div>worker count = {{ number_of_cpu }}<br>
<br></div><div>Don&#39;t mind the correct syntax here, just a high level.<br><br></div><div>What does this do for you? <br></div><div>1. if you just boot up a new vm, and running the tasks above, nginx will be installed and the tool will configure nginx.conf and use whatever # of cpu found for that vm to be the worker count. If 20 servers are 4 core you get 4, and if the rest are 2 cores, you get 2.<br>
</div><div>2. If you alreayd have run the script before, you can run again, and unless you upgrade your system to have more cores, running the same script on the same machine twice should yield no change, ie. idempotent. <br>
<br></div><div>As you can see from #2, this is great for continuous deployment and server management. I can run the same configuration setup on the same set of machine as many times as i want and should yield no side effect, PROVIDED that the system hardware hasnt changed, and that the variables haven&#39;t changed. <br>
<br></div><div>Say you have a task that fetch a github repo changes, you can write a task to fetch either the latest or a specific changes. This ensures system is behaving the way you want. In another words, YOU write a bunch of scripts to tell the system how to setup and beahve, and ask the tool to run the scirpts againsts some servers and the tool should not do different thing as long as the tasks haven&#39;t changed and system dependent variables stay the same.<br>
<br>Get it? <br></div><div><br></div><div>Write tests to test system is not rare, but there must be a very good reason. The only one I have seen is someone trying to debug system problem, that&#39;s all. Others write system tools such as new nagios modules. To test nagios is installed, or a particular configuration is used, writing<br>
<br>def test_nagios_fileA_used(self):<br></div><div>    ip?<br></div><div>    sudo privilege?<br><br></div><div>See, that&#39;s tough, huh. And how do you assert? Oh &#39;this line should be present&#39; in f.read() <br><br>
</div><div>You can essentially running a configuration tool.<br><br></div><div>John<br></div><div><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 24, 2013 at 5:37 PM, Ben Finney <span dir="ltr">&lt;<a href="mailto:ben+python@benfinney.id.au" target="_blank">ben+python@benfinney.id.au</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Rita &lt;<a href="mailto:rmorgan466@gmail.com">rmorgan466@gmail.com</a>&gt; writes:<br>
<br>
&gt; I know that unittest is great for testing code.<br>
<br>
</div>More specifically, unittest is great for unit testing: isolating a small<br>
unit of code and testing whether it gives expected outputs for given<br>
inputs.<br>
<div class="im"><br>
&gt; I was wondering if anyone is using it to test system consistency. I<br>
&gt; manage several hundred systems and I am currently using Nagios<br>
<br>
</div>I think Nagios is more for monitoring, not automated testing. Is that<br>
not correct?<br>
<div class="im"><br>
&gt; but instead I was wondering if unittest would be OK for something like<br>
&gt; this.<br>
<br>
</div>For testing system behaviour, the unittest module is a poor fit since it<br>
is designed to test isolated units of code at the function-call level.<br>
<br>
You would do better to look at behavioural testing tools, like Behave<br>
&lt;URL:<a href="https://pypi.python.org/pypi/behave" target="_blank">https://pypi.python.org/pypi/behave</a>&gt; that can work from assertions<br>
about the behaviour of the whole system.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
 \       “We must find our way to a time when faith, without evidence, |<br>
  `\    disgraces anyone who would claim it.” —Sam Harris, _The End of |<br>
_o__)                                                     Faith_, 2004 |<br>
Ben Finney<br>
<br>
<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>
</font></span></blockquote></div><br></div>