[CentralOH] Namespace packages with Nose test runner
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:
+-__init__.py (namespace version)
The __init__.py file in the atomisator directory contains the "magic" code for namespace packages:
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH