How do you do unittest?

Will Stuyvesant hwlgw at hotmail.com
Sat Aug 2 03:18:58 EDT 2003


> [Raymond Hettinger]
> You can avoid that sort of mambo jambo by avoiding
> unittest.main() and running the tests directly.  I added
> a simple example to the Py2.3 docs:
> 
>    http://www.python.org/doc/current/lib/minimal-example.html

Thanks, I now use unittest.TextTestRunner (what a name!) in
test_mod.py in a test_mod.test function.  Together with a general
test.py in the 'test' directory that does the sys.path.append('..') I
can now run tests in the test directory so I don't have all the
clutter in the source directory, and I don't have to do
sys.path.append('..') in every test_xxx.py, only in the test.py that
looks like:

# To be executed in the 'test' directory
import sys
sys.path.append('..')
import test_mod
test_mod.test()
import test_mod2
test_mod2.test()
...




More information about the Python-list mailing list