By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

doctesting

P: n/a
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:
>>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...

Advice appreciated,

--b
Jan 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.htm...00000000000000

Peter
Jan 2 '07 #2

P: n/a
In article <ma***************************************@python. org>,
belinda thom <bt***@cs.hmc.eduwrote:
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
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

--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>
Jan 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.