How do you do unittest?

Will Stuyvesant hwlgw at
Fri Aug 1 16:33:38 CEST 2003

I have a unittest testfile like this:

----------------------- ---------------------
import sys
import unittest
import mod

class Test_rmlutils(unittest.TestCase):

    def testNormalCase(self):

if __name__ == '__main__':

It is exactly the same as example 17-2 in "Python in a
Nutshell" (PiaN), except for the first two lines.  To
quote PiaN:
" the test module...with a prefix such as 'test_',
and put it in a subdirectory named 'test' of the directory
where you keep the sources."

PiaN did not mention the ugly sys.path.append('..') trick
I had to use when following its advice.  I need to use it
because is in the directory above the 'test'

To run a test from the source directory I have to change
to the 'test' directory and run there from the
commandline.  Okay, I can do that from a batchfile:

----------------------- test.bat ------------------------
cd test
cd ..

But: I would like to get rid of the need for
sys.append('..') and I don't see a nice way to do that, do
you?  Maybe something from a Python script instead of a
DOS script...I am thinking about importing sys there and
then doing some advanced unittest function like
'runsuite(blah, foo)' but I am still reading the unittest
docs and there must be somebody who did this before?

I guess the author of PiaN does not use a 'test' subdirectory 
himself, as it is now the example 17-2 does only work in the 
source directory.

More information about the Python-list mailing list