doctesting

B

belinda thom

Hi,

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:

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...

Advice appreciated,

--b
 
P

Peter Otten

belinda said:
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:


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
 
B

Ben Artin

belinda thom said:
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:


fail even though I've started the script in a directory that contains
file foo.py

import foo looks at sys.path which is based on PYTHONPATH in the environment.
So, one way to do what you want is to have your script modify sys.path before
importing other modules.

hth

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top