views:

813

answers:

6

Basically, growl notifications (or other callbacks) when tests break or pass. Does anything like this exist?

If not, it should be pretty easy to write.. Easiest way would be to..

  1. run python-autotest myfile1.py myfile2.py etc.py
  2. Check if files-to-be-monitored have been modified (possibly just if they've been saved).
  3. Run any tests in those files.
  4. If a test fails, but in the previous run it passed, generate a growl alert. Same with tests that fail then pass.
  5. Wait, and repeat steps 2-5.

The problem I can see there is if the tests are in a different file. The simple solution would be to run all the tests after each save.. but with slower tests, this might take longer than the time between saves, and/or could use a lot of CPU power etc..

The best way to do it would be to actually see what bits of code have changed, if function abc() has changed, only run tests that interact with this.. While this would be great, I think it'd be extremely complex to implement?

To summarise:

  • Is there anything like the Ruby tool autotest (part of the ZenTest package), but for Python code?
  • How do you check which functions have changed between two revisions of a script?
  • Is it possible to determine which functions a command will call? (Somewhat like a reverse traceback)
+2  A: 

Maybe buildbot would be useful http://buildbot.net/trac

dbr
+2  A: 

For your third question, maybe the trace module is what you need:

>>> def y(a): return a*a
>>> def x(a): return y(a)
>>> import trace
>>> tracer = trace.Trace(countfuncs = 1)
>>> tracer.runfunc(x, 2)
4
>>> res = tracer.results()
>>> res.calledfuncs
{('<stdin>', '<stdin>', 'y'): 1, ('<stdin>', '<stdin>', 'x'): 1}

res.calledfuncs contains the functions that were called. If you specify countcallers = 1 when creating the tracer, you can get caller/callee relationships. See the docs of the trace module for more information.

You can also try to get the calls via static analysis, but this can be dangerous due to the dynamic nature of Python.

Torsten Marek
That's exactly what is needed - Thanks!
dbr
+2  A: 

Django's development server has a file change monitor that watches for modifications and automatically reloads itself. You could re-use this code to launch unit tests on file modification.

John Millikin
+7  A: 

autonose created by gfxmonk:

Autonose is an autotest-like tool for python, using the excellent nosetest library.

autotest tracks filesystem changes and automatically re-run any changed tests or dependencies whenever a file is added, removed or updated. A file counts as changed if it has iself been modified, or if any file it imports has changed.

...

Autonose currently has a native GUI for OSX and GTK. If neither of those are available to you, you can instead run the console version (with the --console option).

dbr
+3  A: 

I just found this: http://www.metareal.org/p/modipyd/

I'm currently using thumb.py, but as my current project transitions from a small project to a medium sized one, I've been looking for something that can do a bit more thorough dependency analysis, and with a few tweaks, I got modipyd up and running pretty quickly.

mpstx