doctesting

Peter Otten __peter__ at web.de
Tue Jan 2 04:16:30 EST 2007


belinda thom wrote:

> I'd like to write a tester script that I can place in one place (say
> ~/bin/python/tester.py) and then have it visible to me at the cmd-
> line (by setting the path  variable appropriately). I have had no
> luck in getting it to work, however.
> 
> It appears like the doctest code itself assumes that all modules to
> be imported lie in some directory other than the one I invoked the
> tester.py script from. In particular, simple imports in a .txt file
> like:
> 
>    >>> import foo
> 
> fail even though I've started the script in a directory that contains
> file foo.py
> 
> I only achieve success when I manually copy tester.py into this same
> directory (symlinks don't fix the problem).
> 
> This is a real drag b/c it means I have to copy this tester.py
> routine into _every_ directory that contains a .txt python unit test
> file. From a code-reuse point of view, this is pretty hideous...

For an executable script to be reachable its path must be listed in the PATH
environment variable whereas Python's import mechanism relies on PYTHONPATH
(and ultimately on sys.path).

http://docs.python.org/tut/node8.html#SECTION008110000000000000000

Peter



More information about the Python-list mailing list