[SciPy-dev] Making numpy test work in scikits

David Cournapeau david at ar.media.kyoto-u.ac.jp
Fri Jul 20 02:33:45 EDT 2007


Hi,

    I had a hard time to get the usual numpy tests working inside a 
scikits (because of setuptools): I wanted to keep the usual numpy tests 
infrastructure (each package has a tests directory where all the tests 
are), while being able to use them with python setup.py test. Below is a 
an quick explanation how I did it:

    - foo/scikits/foo  -> this  is a typical "scipy package", in the 
sense that you can use the same layout for tests  as in a scipy package.
    - foo/setup.py -> use the test_suite argument of the setup function, 
with the value "tester"
    - foo/tester.py -> this defines a function additional_tests, which 
is supposed to return a unittest.TestSuite. I use NumpyTest to find all 
the tests in the package foo, and make a TestSuite from it; I had to use 
a private function, though, but maybe adding public API in numpy would 
be possible. The module tester boils down to this:

from numpy.testing import NumpyTest

def additional_tests():
    # XXX: does this guarantee that the package is the one in the dev 
trunk, and
    # not scikits.foo installed somewhere else ?
    import scikits.foo
    np = NumpyTest(scikits.foo)
    return np._test_suite_from_all_tests(np.package, level = 1, 
verbosity = 1) 

With this, you can call all the tests with python setup.py test (which 
is the point of all this, actually), but:
    - I don't know much about unittest, though, so this may be not ideal 
but is the only way I found to make is work without touching anything 
else than the setup.py file.
    - There may be a way to make this a bit more automatic (I don't like 
the fact that I have to give the name of the package in 
additional_tests, for example)
    - I didn't find a way to give argumements for tests in command line 
(setuptools does not seem to support it for the test command).

    cheers,

    David



More information about the SciPy-Dev mailing list