Import path for unit tests
Ben Finney
bignose+hates-spam at benfinney.id.au
Fri Dec 2 22:50:16 EST 2005
Duncan Booth <duncan.booth at invalid.invalid> wrote:
> Ben Finney wrote:
> > What is the common idiom here? I can conceive of several possible
> > ways to get around it, all of which seem hackish to some degree.
>
> I don't know if it is the common idiom, but I tend to write:
>
> TESTDIR = os.path.dirname(os.path.abspath(__file__))
> PROJECTDIR = os.path.dirname(TESTDIR)
> if not TESTDIR in sys.path:
> sys.path.insert(1, TESTDIR)
> if not PROJECTDIRDIR in sys.path:
> sys.path.insert(1, PROJECTDIR)
Thankyou, that works better than what I was doing.
But it's my idea of "hackish" :-) It works, and is comprehensible. But
it's pretty heavyweight for something I need to do all the time (i.e.
writing unit test modules for various projects).
Anyone else have a preferred way of doing this? Or will I have to wait
until PEP 328 is integrated?
<URL:http://www.python.org/peps/pep-0328.html>
--
\ "Laurie got offended that I used the word 'puke.' But to me, |
`\ that's what her dinner tasted like." -- Jack Handey |
_o__) |
Ben Finney
More information about the Python-list
mailing list