473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

doctesting

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
2 1238
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric Mahurin | last post by:
Noob here. Just got into python a little over a week ago... One of the (unique?) things I really like about python is the concept of doctesting. But, now I want more! Here's what I'd like to...
0
by: Alia Khouri | last post by:
I was wondering the other day how other pythonistas incorporate doctests into their coding practices. I have acquired the habit of keeping an editor open in one window and an ipython instance open...
3
by: Steven D'Aprano | last post by:
I have a function in my module: def selftest(verbose=False): import doctest doctest.testmod(verbose=verbose) When I run it, it fails to find any of my doc tests, including the tests in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.