home‎ > ‎

django-hudson Tutorial

1. Introduction


There are a lot of ways to enable continuous integration with your django project. But most of them require a lot of time to configure and setup ci server and make changes in your django project.

This tutorial introduces a new way to enable continuous integration for django project, with minimal projects modifications by means of with django-hudson.

Previously, ad-hoc integration django with hudson required using nose testing frameworks instead of django native unittests.  Since nose project uses custom test loader it leads to a lot of problems with django code  - duplicate signals subscriptions, module loading and other test realted errors. Django-hudson uses the standard unnittest runner, so the code under test works like in production. No difference between django-hudson run and manage.py tests keeps your hands free for real work. 

2. Configuring django project


To enable django_hudson you need only to add django_hudson to INSTALLED_APPS in settings.py.

Now running python manage.py hudson will do the same job as python manage.py tests, but also will create reports folder in the root of your django project with hudson parsable pylint, test coverage and tests reports.

This tutorial doesn't cover the library dependency management and deployind your django project on external server. Basically you could setup the CI server as you did in your local environment.

But if you prefer automatically installation and configuration dependencies on CI server, you could easily add virtualenv support for you project.

Install virtualenv, substitute manage.py file with the contents of this snippetin the root of you django project. Add requirements.pip file with following content:

Django
django-hudson
# any other libraries required for you project

Running python manage.py update_ve will create local folder .ve with the required libraries for your project. Running this command on other servers will help to sync the external dependencies.

3. Configuring hudson

After Hudson fresh installation you'll need to install two required plugins: Violations plugin for parsing pylint reports,  and Cobertura Plugin for showing the code coverage. Install these plugins via Manage Hudson -> Manage Plugins -> Available.   

Start new job with creating free-style project:


After configuring the repository access, set up the build trigers. Poll SCM will run the build if any changes in repository are found. The line */5 * * * * means checking repository every 5 minutes.



Select "Add build step -> Execute shell". Add comands to setup environment (in our case it is 
python manage.py update_ve), and the run tests command (python manage.py hudson)


Specify the location of test reports - reports/TEST-*.xml files.


Pylint report is located in reports/pylint.report



Test coverate reports are in reports/coverage.xml


That's All!

4. Results


Press "Build Now" and see what you've got:

Pylint reports for each build, which show what warnings/erros are new for each build
 

Nice code coverage reports, showing the total coverage, and colored file listing.


And of course the test results and output.









Comments