[TIP] How do I get nose to add the cwd to sys.path?

Grig Gheorghiu gheorghe_gheorghiu at yahoo.com
Thu Nov 13 14:33:40 PST 2008


--- On Thu, 11/13/08, Daryl Spitzer <daryl.spitzer at gmail.com> wrote:

> When I run `nosetests` it finds the tests in the .py files
> in tests/,
> but I get an import error in the tests when they try to
> import the
> module they're testing (which is in the parent
> directory of the tests
> in "tests").  I've tried `nosetests -w .`
> (and other variants) but I
> get the same import errors.
> 

I do that 'by hand'. In the __init__.py file in the tests directory I have these 2 lines:

import os, sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

Grig



More information about the testing-in-python mailing list