[TIP] How do I get nose to add the cwd to sys.path?
Daryl Spitzer
daryl.spitzer at gmail.com
Sat Nov 15 15:57:29 PST 2008
On Sat, Nov 15, 2008 at 10:52 AM, jason pellerin <jpellerin at gmail.com> wrote:
> Basically, python says that absolute imports are preferred, and if you
> run nosetests from inside a package (which is not really the right
> thing to do anyway)...
Why is that not really the right thing to do? In my case, I am
running nosetests from inside a package because I'm adding unit tests
to a subpackage of legacy code that currently has no unit tests. So
to me it seems reasonable to run nosetests from the directory that
contains the (only) "tests" subdirectory.
> ...they won't work unless nose figures out that it's inside of that
> package and adds the package root to sys.path. I guess it would be
> possible to also add cwd in that case -- it hasn't been done that way
> so far because nobody has asked for it, and I don't use relative
> imports or run nose inside of packages myself. ;)
My first reaction on reading this was to ask you how to ask for it.
But after a little more study I now see I'm better off using absolute
imports.
Thanks.
--
Daryl
On Sat, Nov 15, 2008 at 10:52 AM, jason pellerin <jpellerin at gmail.com> wrote:
> On Fri, Nov 14, 2008 at 6:42 PM, Kumar McMillan
> <kumar.mcmillan at gmail.com> wrote:
>> On Thu, Nov 13, 2008 at 4:27 PM, Daryl Spitzer <daryl.spitzer at gmail.com> wrote:
>>> Here's what the directory structure looks like:
>
>>> I'm running `nosetests` from the foo directory.
>
> [ and 'import bar' doesn't work ]
>
>> I'd suggest bringing this up. I'm curious what Jason's explanation is.
>
> Basically, python says that absolute imports are preferred, and if you
> run nosetests from inside a package (which is not really the right
> thing to do anyway) they won't work unless nose figures out that it's
> inside of that package and adds the package root to sys.path. I guess
> it would be possible to also add cwd in that case -- it hasn't been
> done that way so far because nobody has asked for it, and I don't use
> relative imports or run nose inside of packages myself. ;)
>
> JP
>
More information about the testing-in-python
mailing list