wrestling with unittest paths..needs suggestions

Raaijmakers, Vincent (GE Infrastructure) Vincent.Raaijmakers at ge.com
Thu Mar 11 14:22:56 EST 2004


In my enthusiasm of separating my unittests from my business logic modules, I encounter some problems in my path setting. Can solve them, but so ugly. Needs suggestions in the right way to do it.


This is my problem.
path to main class... say: 

path = /home/workspace/src/foo
There is a module Foo.py
/home/workspace/src/foo/Foo.py

My unittest is in:
/home/workspace/src/test/foo
so:
/home/workspace/src/test/foo/FooTest.py

Now, in order to test Foo in FooTest, I added the path to Foo.py in FooTest:

	### FooTest.py ###
import os, sys
testpath = os.path.abspath('/home/workspace/src/foo')
sys.path.append(testpath)

Well, it works but if I have to do that for every test module that I write.. 
Very nasty..

Also, if I would like to write an AllTests.py in /home/python/test/, the solutions of finding the paths to my business logic should still work of course.

So I tried to look around for better solutions, like the use of __init__.py but just can't get it to work without the ugly path setting in my unittest module.

My hope is that someone here can tell me what THE correct solution is here.

Thanks in advance,
Vincent




More information about the Python-list mailing list