[TIP] Testing a daemon with coverage (nose)

Alfredo Deza arufuredosan at gmail.com
Thu May 7 05:44:34 PDT 2009


I have just started to get into the habit of testing everything that I code,
and a good friend of mine suggested the coverage plugin when using

Right now I am working on a Daemon module for Python scripts. The module,
when imported will make the current process detach from the terminal and run
in the background as a daemon.

When trying to test the module (importing it to test_module.py) I fail to
correctly test any actions since it will convert test_module.py into a

To circumvent this problem I created a "daemon script" (test_script.py) that
would import the daemon module and effectively run in the background.

The tests would check upon this daemon and the actions the module should be
doing when working correctly (write to a file, kill a process etc).

And this solution works fine for testing, but the "--with-coverage" flag
does not cover the daemon module at all.

When going further and specifying the package with
"--cover-package=daemonModule" I get 0% coverage. I'm thinking this is
expected since I am not importing the daemon module within test_module.py
but rather on the daemon test script (test_script.py).

And just to avoid some confusion, this is what I have:
test_script.py => Script that will correctly daemonize so I can test
test_module.py => Where all the tests go. Can't import the daemon module
here or this will detach from the terminal.

Do you guys know any other way that I could effectively test the daemon
while still being able to maintain the Coverage plugin with a nice
percentage value?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/testing-in-python/attachments/20090507/1ac1f28b/attachment.html 

More information about the testing-in-python mailing list