Django continuous integration with Hudson and Nose
I started off using Joe Heck’s great Python and Hudson writeup as a guide.
Before you get Hudson up and running, you’ll first want to create a test settings module for your application. Here’s a sample:
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.
And then our coverage report, you’ll need the Cobertura plugin for this:
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: