ImportError on subpackage when running setup.py test

I'm trying to create an install package for a Python project with included unit tests. My project layout is as follows:

setup.py
src/
    disttest/
        __init__.py
        core.py
tests/
    disttest/
        __init__.py
        testcore.py

My setup.py looks like this:

from distutils.core import setup
import setuptools

setup(name='disttest',
      version='0.1',
      package_dir={'': 'src'},
      packages=setuptools.find_packages('src'),
      test_suite='nose.collector',
      tests_require=['Nose'],
      )

The file tests/disttest/testcore.py contains the line from disttest.core import DistTestCore.

Running setup.py test now gives an ImportError: No module named core.

After a setup.py install, python -c "from disttest.core import DistTestCore" works fine. It also works if I put import core into src/disttest/__init__.py, but I don't really want to maintain that and it only seems necessary for the tests.

Why is that? And what is the correct way to fix it?

6
задан Henrik Heimbuerger 14 April 2011 в 10:45
поделиться