Automated python testing with nose and eclipse

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.

2 Trackbacks

You can leave a trackback using this URL: http://www.machine-envy.com/blog/2006/07/29/automated-python-testing-with-nose-and-eclipse/trackback/

  1. [...] Etter en masse leting fant jeg endelig svaret her [...]

  2. By Python Development » Terrarum on July 19, 2010 at 8:04 am

    [...] updates… Links of InterestAutomated python testing with nose and eclipse – machine-envyNotes on using pip and virtualenv with Django « SaltyCrane BlogDisqus: The Official Blog, Partial [...]

9 Comments

  1. 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

    Posted July 29, 2006 at 4:09 pm | Permalink
  2. James

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

    Posted July 29, 2006 at 7:36 pm | Permalink
  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.

    Posted August 5, 2007 at 11:09 pm | Permalink
  4. Bruno Rezende

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

    Posted June 17, 2008 at 1:32 pm | Permalink
  5. James Casbon

    Bruno: I don’t think you can get the PYTHONPATH from eclipse using an external tool. But I just posted a recipe to nose-users that will allow you to use the python you configured there:
    ttp://groups.google.com/group/nose-users/browse_thread/thread/910b1d61933520d7

    Posted August 21, 2008 at 8:52 am | Permalink
  6. Chaim Krause

    This is a great idea. I do all my Python development in Eclipse with Pydev and just started using nose. This will save me some time. Thanks for posting it.

    Posted October 10, 2008 at 5:30 pm | Permalink
  7. van

    Great recipe.

    The only issue I found until now is that when “Refresh Automatically” option is set in Eclipse preferences and nosetests is executed with “–with-coverage” option and during “Auto Builds”, then the builder runs indefinitely… I guess it is because of .coverage file is re-generated in the project directory.

    Posted April 17, 2009 at 3:48 pm | Permalink
  8. Automated python testing with nose and eclipse | machine-envyHey, nice post, very well written. You should write more about this.

    Posted June 25, 2009 at 10:02 am | Permalink
  9. Hmm… I read blogs on a similar topic, but i never visited your blog. I added it to favorites and i’ll be your

    constant reader.

    Posted August 4, 2009 at 1:03 pm | Permalink

Post a Comment

Your email is never shared. Required fields are marked *

*
*