I use eclipse with the excellent pydev for my coding. Yes, I know I should be using emacs but at work I’m forced to use windows so I like the way eclipse insulates me from the OS. Also, I could never get over the ugliness of emacs default fonts (anyone know to make it look better?). I also like not having to think about versioning, as subclipse does a great job of doing it all for me.

I also use nose for testing. Even written a few plugins (eg one that dumps the test results into a nice excel spreadsheet to give to the QA department) and contibuted a few patches. The test attributes are a great feature, and it allows you to mix unittest, simple test methods and doctests without thinking about it. However, I was inspired by this post on automating nose whenever a source file changes to look at doing the same in eclipse. Turns out, its easier than I could have imagined.

Under project properties, define a new ‘program’ builder. Set the location to the nosetests script, set its working directory to ${project loc}, append any command line options you want (eg –with-coverage -a !slow,!gui) and then, under the build options tab, tick the ‘launch in background’ and ‘during auto builds’. Now, whenever you save the changes to a file, the test results will come out in the console.

Unfortunately, it seems eclipse cannot share builders between projects. However, you can setup nose as an external tool. Then, when you need it as a builder you can import it. It’s also quite nice to have an external tool set up that runs nose only on the selected file. To do this set up an external tool as before, but instead set working directory to {$container loc} and put {$resource loc} in the command line arguments.


  1. Jeff Winkler

    Very cool.. what about other file types in the same directory, would they trigger the build?
    I ues Kid for HTML generation. I’ve added the .kid into nosy: changing the template regenerates the HTML, and a meta refresh tag reloads the page in the browser. So you can make a change in Eclipse and see the results in the browser in ~30 seconds.

    Are you familiar with showmedo (http://showmedo.com/videos/python)? A screencast of this technique would be great.
    - Jeff

  2. James

    Yeah, the eclipse auto builder runs whenever any file changes so it will pick up the html changes too.

  3. Kevin

    If the nosetests script is on your execute path, you don’t have to specify its exact location by using

    ${system_path:nosetests}

    as the location. This is very helpful when a project file is shared across different platforms, as the path is not hard-coded.

  4. Bruno Rezende

    Nice recipe. Do you know if it is possible to automatically set PYTHONPATH enviroment using the pydev Pythonpath settings?

  1. 1 blog.luguber.info » Blog Archive » Automated python testing with nose and eclipse

    […] Etter en masse leting fant jeg endelig svaret her […]



Leave a Comment