Pages

Sunday, 3 March 2013

TDD framework with inotifywait and tox

So let's say, you want to do TDD. It means, that whenever you change something, you would want to run the tests. Okay, it sounds like a boring task, so let's automate it, to meet the Agile practices. So a user-space utility, called
inotifywait
will be used. This blocks, until some even happens with the monitored files. As my source code is in git, I will use:
git ls-files
to get the files to be watched. Okay, let's put it together:
$ git ls-files | inotifywait -q --fromfile -
This blocks, until something happens to a file that is watched. Let's save a file with vim, that is under version control, and see that inotifywait unblocks, and outputs:
fs/__init__.py MOVE_SELF 
Okay, that works, so let's use it as a framework to run our tests:
$ while true; do git ls-files | inotifywait -q --fromfile -; tox; done
As you add a new file to git, that will result in a change in .gitignore, so it should be automatically picked up by our framework. Tox gives you pretty colours as well!

No comments:

Post a Comment