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

Daryl Spitzer daryl.spitzer at gmail.com
Thu Nov 13 13:49:04 PST 2008

After the replies to my "Where to put unit tests?" question (thanks
everyone), I renamed my "UnitTests" subdirectory to "tests" and
installed nose.

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.

Up until now, I've been using some code to run my tests that I stole
from Michael Foord's Mock, which (in a file called alltests.py in the
"UnitTests" subdirectory) contains:

if not os.getcwd() in sys.path:

I guess I need to figure out how to get nose to do the same.


More information about the testing-in-python mailing list