November 21, 2009
Django continuous integration with Hudson and Nose
At work we’ve decided to use Hudson for our continuous integration server.
I started off using Joe Heck’s great Python and Hudson writeup as a guide.
But to get really good reporting, including a coverage report, you’re going to want to use Nose, django-nose, and my nose-xcover plugin.
Before you get Hudson up and running, you’ll first want to create a test settings module for your application. Here’s a sample:
With that in place you’ll want to set up a separate test requirements file for pip. If you’re not using pip, I can’t be held responsible if the central committee gets ahold of you.
Why use my fork of nose? We’ll get to that in a second. First let’s set up our build script.
- We change into Hudson workspace set up for this build
- Set up a virtualenv for our project
- Activate it
- Install our application’s requirements
- Install our application’s test requirements
- Assuming you have a properly constructed setup.py, this command will symlink it into your virtualenv’s site packages
- Finally run our tests, using our test settings.
The –with-coverage option tells nose we want to capture coverage information. The –cover-package option tells nose we only want reporting on our application. The –with-xunit option will generte a nosetests.xml file in our workspace with the results of the test run.
Finally, the –with-cover-xml option is an option I added to nose’s coverage plugin, and the reason why I’ve got my fork listed in our test-requirements.pip. Finally, the –with-xcoverage option activates my nose-xcover plugin. It outputs an XML coverage report that Hudson can use, and it’ll honor the –cover-package option you specified earlier, so your coverage percentage won’t be artificially lowered, or inflated, by third-party code you use.
Now let’s configure Hudson to use the two XML reports we’re generating.
First the test pass/fail report.
![Config [Hudson].jpg](http://heisel.org/blog/wp-content/uploads/2009/11/Config-Hudson.jpg)
And then our coverage report, you’ll need the Cobertura plugin for this:
![Config [Hudson]-1.jpg](http://heisel.org/blog/wp-content/uploads/2009/11/Config-Hudson-1.jpg)
That’s right, you’ll also want the Chuck Norris plugin. Why? Because Chuck Norris can divide by zero. That’s why.
Also, I’d highly recommend the Green balls plugin, because Hudson’s default of blue == pass just doesn’t fly with me, or Chuck.
While we’ve been setting up Hudson, I had another build in the oven baking using the recipe above. Let’s see how it turned out:
![Dummy [Hudson].jpg](http://heisel.org/blog/wp-content/uploads/2009/11/Dummy-Hudson.jpg)
Editor’s note: I updated this post to use my nose-xcover plugin and not my fork of nose.
Filed under: Django,Programming,Python,Technology
Next: For Christmas, vintage photos
Previous: Setup Django with mod_wsgi on your Mac
Related
-
http://www.rhonabwy.com/wp/ Joe Heck
-
http://heisel.org Chris
-
Stavros
-
http://heisel.org Chris Heisel
-
http://heisel.org Chris
-
Stavros
-
Stavros
-
Stavros
-
http://jacob.champness@gmail.com jacob
-
http://heisel.org Chris
-
Jacob
-
http://www.caktusgroup.com/blog/ Tobias McNulty
-
Tim
-
James English
-
James English
-
http://twitter.com/c089 Christoph Neuroth
-
Daniel Watkins