Tom Harris wrote:
> I like to have my tests in a subdirectory for a project, so directory
> 'foo' would have a subdirectory 'test'. The tests in 'test' should be
> able to load module foo.py in it's parent directory, with a
> sys.path.insert(0, '..'). That's the way I did it with unittest anyway.
> Example below fails unless I insert a '.' instead of '..' into sys.path.
>
> file 'foo/foo.py':
> def a(): return 1
>
> file 'foo/test/test_foo.py':
> import sys
> sys.path.insert(0, '..')
> import foo
>
> def test_1():
> assert foo.a() == 1
>
> Now I'm quite happy to type import sys; sys.path.insert(0, '.') at the
> head of all my test files, but am I missing something?
I'm pretty new at this, but here's what I have at the head of all my
test/test_foo.py files:
import sys
sys.path.append('..')
It works. I wonder if inserting it at the 0 spot in the list is the problem
(as opposed to the end like I'm doing)? The first item in the path list
appears to be something special as I read the docs.
Michael
_______________________________________________
py-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/py-dev