Running all unit tests

D'Arcy J.M. Cain darcy at druid.net
Fri Feb 6 21:52:29 EST 2009


On Fri, 06 Feb 2009 21:11:15 -0500
Jason Voegele <jason at jvoegele.com> wrote:
> I'm working on my first substantial Python project, and I'm following a fully 
> test-first approach.  I'd like to know how Pythonistas typically go about 
> running all of their tests to ensure that my application stays "green".

I check in my unit tests to CVS along with the code and name the unit
test files with the form "TEST_xxx.py" to identify them.  I then put
the following script into my crontab so that my tests are run every
day.  I make the TEST_xxx.py executible so that I can always run a
specific test at any time if I am working on specific code.

Note that the script only sends email when something goes "red" so I
don't have to wade through "green" reports every day.  The errors stand
out that way.

#! /bin/sh
# $Id: run_unit_tests,v 1.4 2008/06/23 01:07:24 darcy Exp $

# This script runs all of the unit tests

if [ $# -lt 2 ]
then
    echo "Usage: $0 <base directory> [<email address>]"
    exit 1
fi

cd $1
trap "rm -f /tmp/run_tests.$$" 0
HOST=`hostname`

find -L . -type f -name 'TEST_*.py' | while read TEST
do
    $TEST > /tmp/run_tests.$$ 2>&1 ||
        mail -s "TEST failure on $HOST: $TEST" $2 < /tmp/run_tests.$$
done


-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list