[TIP] Nose Importer

Alfredo Deza alfredodeza at gmail.com
Wed Apr 7 14:11:13 PDT 2010


Hi,

I am having some issues with the Nose importer.

My project layout is set as follows:

/project
/project/lib
/project/tests

When I run 'nosetests -v' in /project everything runs OK (tests import from
within 'lib').

But when I am within /project/tests 'nosetests -v' fails with an ImportError
exception saying it cannot import the
files from lib on only *one* of the test files.

However, if I take the same test file that is throwing exceptions and run it
against nose, it completes the tests successfully:

'nosetests -v test_permissions.py'

It also works fine when calling it via python:

'python test_permissions.py'

The one file that test_permissions.py is trying to import but is failing is:
'permissions', and it does so by:

sys.path.append('../')
from lib import hg, permissions, upgrade

I am not sure why it would be able to import 'hg' and 'database', but fail
to import 'permissions', and only when it runs all tests within the tests
directory.

Here is a copy of one of the exceptions:

======================================================================
ERROR: Failure: ImportError (cannot import name permissions)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/nose/loader.py", line 382, in
loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python2.6/dist-packages/nose/importer.py", line 39,
in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python2.6/dist-packages/nose/importer.py", line 86,
in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/alfredo/pacha/tests/test_permissions.py", line 10, in <module>
    from lib import hg, permissions, database
ImportError: cannot import name permissions



Maybe I need to import differently? But then again... *why* it works when I
call it directly? I basically want
to be able to run from either /project or /project/tests with the same
results.



-- 
Alfredo Deza
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20100407/1ec74d5c/attachment.htm>


More information about the testing-in-python mailing list