June 20, 2009

Pywatch: Run tests when your code changes

I’m happy to announce that pywatch is ready for use, I think.

What does it do? It’s both a Python module and a com­mand line client that allow you to run arbi­trary shell com­mands when­ever changes occur in a list of spec­i­fied files.

Here’s an exam­ple:

pywatch --help
Usage: pywatch [options] "command" file1 file2 ...

Options: -h, --help show this help message and exit -v, --verbose Output timestamp when commands are run. chris@pinko:~/Code/pywatch$ pywatch -v ./bin/test src/pywatch/watcher.py src/pywatch/tests.py

Running commands at 2009-06-20 12:00:13.226711 Running zope.testing.testrunner.layer.UnitTests tests: Set up zope.testing.testrunner.layer.UnitTests in 0.000 seconds. Ran 4 tests with 0 failures and 0 errors in 2.003 seconds. Tearing down left over layers: Tear down zope.testing.testrunner.layer.UnitTests in 0.000 seconds.

Running commands at 2009-06-20 12:00:34.422557 Test-module import failures:

Module: pywatch.tests

Traceback (most recent call last): File "/home/chris/Code/pywatch/src/pywatch/tests.py", line 1, in import makethistestblowup ImportError: No module named makethistestblowup

Test-modules with import problems: pywatch.tests Total: 0 tests, 0 failures, 0 errors in 0.000 seconds.

Running commands at 2009-06-20 12:00:44.600708 Running zope.testing.testrunner.layer.UnitTests tests: Set up zope.testing.testrunner.layer.UnitTests in 0.000 seconds. Ran 4 tests with 0 failures and 0 errors in 2.006 seconds. Tearing down left over layers: Tear down zope.testing.testrunner.layer.UnitTests in 0.000 seconds.

So far I’ve been using it to auto­mat­i­cally run tests on per­sonal projects, includ­ing pywatch and base­boards.

You could use it to run other arbi­trary com­mands when­ever you change a file, but run­ning tests was the par­tic­u­lar itch I was trying to scratch.

It’s avail­able at GitHub and PyPI

Filed under: Programming, Projects, Python, Pywatch

Next:
Previous:

Related

Comments