Friday, April 10, 2009

unittest is ...

Okay, the python unittest module is awesome, but the titles are getting repetitive. This little script will make running your unit tests even easier:

test.py

#!/usr/bin/env python

import unittest
import sys

for module in sys.argv[1:]:
done = False
while not done and module != "":
try:
exec('import ' + module)
done = True
except Exception:
module = module.rpartition('.')[0]


unittest.main()



This will allow you to run any unit tests in any module from the command line.


test.py mypackage.test yourpackage.test
test.py mypackage.test.TestXYZ.testRun



No comments:

Post a Comment