Search code examples
pythonnosetests

nosetests with namespace packages


I have two packages in the same namespace with tests, the structure is like this:

Package-1/namespace/__init__.py
Package-1/namespace/module1/__init__.py
Package-2/namespace/__init__.py
Package-2/namespace/module2/__init__.py
Package-2/tests/foo_test.py

Package 1 is properly installed using pip. Now Package 2 depends on Package 1, so foo_test contains the line

import namespace.module1

When I try to run nosetests ./tests/foo_test.py from the directory Package-2 I get an import error because Python complains that it did not find namespace.module1. I am quite sure that the problem is that it tries to search the path Package-2/namespace for the directory module1 which is of course not present. I would like Python to load module1 from the installed packages and not search for it in the current path.

I am not entirely sure, but I think that here a similar issue is explained but to my understanding this should have been fixed. Does anybody have an idea how to work around this? Or am I supposed to structure things differently?


Solution

  • There is a solution for this, at least in Python 3.3+. The __init__.py files that are present in Package-i/namespace/ have to be deleted. I don't understand exactly why that solves the problem but it works in my case...