In which I once again indulge my obscure command-line fetish.
I often spend hours of my day cycling through:
- Edit code and its unit tests
- Save my changes
- Push a button or change window focus to explicitly re-run the code’s unit tests.
Oh frabjous day, the grinding manual labour of the last of these three steps can now be banished forever, courtesy of rerun, a command line Python script that re-runs a given command whenever it detects changes to any of the files in the current directory, or its subdirectories.
Update: It’s Python 2.7, and works great on Windows XP, Macs and Ubuntu.
For example: I had previously bound f6 in Vim to ‘run the current file’s unit tests.’ Now I’ve bound shift-f6 to ‘rerun the current file’s unit tests in a new console window.’ This pops up a new window showing the test results. I then continue editing in Vim, and whenever I hit save, the unit tests are re-run in the other window. All the while the focus stays on my editor. It’s really sweet!
Thanks for the original idea goes to to the bash command ‘watch’, and an old (now offline) blog post by Jeff Winkler.
Pingback: tartley.com : Testwatcher
Great idea! Thanks for sharing. :)
This is like “–looponfail” option on py.test except way cooler. :)
Under Linux (and MacOSX too I guess), you can use the “watch” command to keep your tests running while you code.
I often have my screen split in half, my text editor on one side, and my terminal running “watch -n 1 ./bin/test” on the other side, very useful.
@Jonathan Ballet: Hey. Yeah, ‘watch’ is a great tool, in many situations it’s exactly what you need. That’s why I mentioned it in the original post! :-)
This replacement is intended for those times I’m developing on Windows, and also I don’t want to actually re-run the tests unless something’s actually changed. Polling the file stats seems to be much cheaper, so it allows for more rapid polling without eating all the CPU.
When you’re on Linux, you have the lovely inotify. I installed inotify-tools, and now I have this shell script:
#!/bin/bash
set -x
while true; do
nose whatever blah
inotifywait -e modify *.py
done
In Linux you can use incron to launch jobs upon new files or file modifications incron
Have you checked out Nosyd?
http://pypi.python.org/pypi/Nosyd/0.0.5
I’ve been using the inotify tools in a loop to do the same thing.
while true ; do clear ; printf “Test run at %s\n” “$(date +’%F %T’)” ; python ./setup.py test ; inotifywait -e create -e modify -e delete -t -r . ; done
Not sure if it’s much help, but autospec/autotest do a similar thing in Ruby that might be worth looking into for ideas :)
http://www.zenspider.com/ZSS/Products/ZenTest/
Sounds like there’s a few things there I should be reading about. Thanks heaps for the pointers, people.