Python package structure, setup.py to run unit tests

I’m not sure if I’m ordering the package structure correctly or using the necessary parameters in setup.py, because I get errors when trying to run unit tests.

I have a structure like this:

/project /bin /src /pkgname __init__.py module1.py module2.py /tests __init__.py test1.py test2.py 

My setup.py looks like this:

 #!/usr/bin/env python from setuptools import setup, find_packages setup(version='0.1', description='Trend following library', author='Nate Reed', author_email='nate@natereed.com', packages=find_packages(), install_requires=['numpy'], test_suite="tests", ) 

When I run 'python setup.py test', I get:

 nate@nate-desktop:~/PycharmProjects/trendfollowing$ sudo python setup.py test running test running egg_info writing requirements to UNKNOWN.egg-info/requires.txt writing UNKNOWN.egg-info/PKG-INFO writing top-level names to UNKNOWN.egg-info/top_level.txt writing dependency_links to UNKNOWN.egg-info/dependency_links.txt reading manifest file 'UNKNOWN.egg-info/SOURCES.txt' writing manifest file 'UNKNOWN.egg-info/SOURCES.txt' running build_ext Traceback (most recent call last): File "setup.py", line 11, in <module> test_suite="tests", File "/usr/lib/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/lib/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/usr/lib/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/usr/lib/python2.6/dist-packages/setuptools/command/test.py", line 137, in run self.with_project_on_sys_path(self.run_tests) File "/usr/lib/python2.6/dist-packages/setuptools/command/test.py", line 117, in with_project_on_sys_path func() File "/usr/lib/python2.6/dist-packages/setuptools/command/test.py", line 146, in run_tests testLoader = loader_class() File "/usr/lib/python2.6/unittest.py", line 816, in __init__ self.parseArgs(argv) File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs self.createTests() File "/usr/lib/python2.6/unittest.py", line 849, in createTests self.module) File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/lib/python2.6/unittest.py", line 587, in loadTestsFromName return self.loadTestsFromModule(obj) File "/usr/lib/python2.6/dist-packages/setuptools/command/test.py", line 34, in loadTestsFromModule tests.append(self.loadTestsFromName(submodule)) File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName parent, obj = obj, getattr(obj, part) AttributeError: 'module' object has no attribute 'test1' 

Do test names need to match module names? Are there other conventions that I need to follow in my package structure?

+56
python testing setuptools
May 28 '11 at 19:51
source share
1 answer

With some trial and error, I found the cause of this problem. Test names must match module names. If there is a test "foo_test.py", there must be a corresponding module foo.py.

I found some recommendations for organizing the package structure that helped me refactor my package into a structure of which I was sure.

+46
May 28 '11 at 23:42
source share



All Articles