[CentralOH] Namespace packages with Nose test runner

Mark Erbaugh mark at microenh.com
Thu Jun 16 15:32:22 CEST 2011

I'm having trouble getting nosetests to find my unittests, or finding the namespace'd package code to be tested.  I'm working from code adapted from "Expert Python Programming" by Ziade.

This is the atomisator project. The initial namespace package is atomisator.parser.  This is on a Mac. Here's the relevant directory structure:

+-packages (directory)
   +-atomisator.parser (directory)
      +-atomisator (directory)
         +-__init__.py (namespace version)
         +-parser (directory)
           +-test (directory)

The __init__.py file in the atomisator directory contains the "magic" code for namespace packages:

# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
except ImportError:
    from pkgutil import extend_path
    __path__ = extend_path(__path__, __name__)

If I run nosetests fro the parent (project) directory, it doesn't find the tests in the atomisator.parser/atomisator/parser/test folder. I think this is because __init__.py files are missing from the packages and packages/atomisator.parser directories. If I place __init__.py files there, the tests fail with an ImportError: "No module named atomisator". I've tried both empty __init__.py files as well as ones with the "magic" code above.

I can get the nosetests to run if I launch nosetests with -w packages/atomisator.parser (-w sets the source directory), but only if there are no __init__.py files in packages and packages/atomisator.parser.

If I launch a python interpretor in the project directory, it can successfully import the atomisator.parser package.

The atomisator.parser package was installed using python setup.py develop (which puts a symlink in the local site-packages directory).

The easiest thing that I have found that works is to cd to the packages/atomisator.parser directory (or further into atomisator or atomisator/parser) and run nosetests from there.

I'm obviously trying lots of things here (virtualenv, namespace packages, nosetests, setuptools) and I'm not clear on all the ramifications of all, but I do have something that I can work with.

I know others have mentioned virtualenvwrapper and fabric. Is it time to add another package to the mix?

Thoughts, suggestions?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20110616/95a9d2ad/attachment.html>

More information about the CentralOH mailing list