[SciPy-dev] Making numpy test work in scikits
David Cournapeau
david@ar.media.kyoto-u.ac...
Mon Jul 23 21:05:01 CDT 2007
Matthieu Brucher wrote:
>
> Ok, I managed to make it work by doing the following:
>
> def test_suite(*args):
> # XXX: this is to avoid recursive call to itself. This is an
> horrible hack,
> # I have no idea why infinite recursion happens
> otherwise.
> if len(args) >
> 0:
> import unittest
> return
> unittest.TestSuite()
> return NumpyTest().test(level = -10)
>
> Now, I have to understand why it does not work when I give the
> all=True
> argument to NumpyTest().test. I am starting to think it would be much
> easier to build test suite by hand for each test script...
>
>
> I just tried to use this for openopt scikit, and strangely the first
> time it didn't work with testall(), the second time, it worked...
> I found something strange though (latest svn). When the level is
> positive, the tests are found and run, but when the level is negative,
> the files are found, but not the tests (it indicates Found 0 tests for
> ....py). Is that correct ?
It is intended if you read the docstring (I totally missed it too, at
first). If level is negative, then it is equivalent to returning all the
test corresponding to abs(level) in a test suite, without running them.
As I do not want to run the tests, just the testsuite, I passed level
-10 (which is supposed to return all the tests at all level, if I
understand correctly). I agree this is not really intuitive.
> I thought the same number of tests should have been found.
> What is more, if specific data is needed for the test (and is in the
> same folder), you have to specify the full path in your test file
> because the current path is set to the folder where the test suite is
> run, not where the current test is placed. It's not due to Numpy, I
> know, but it adds a burden :|
Are you aware of set_local_path ? I used it when I need to use the same
function/global variables accross several test files. You can see an
example in the learn scikits (scikits/learn/machine/em/test_densities).
set_local_path()
# import modules that are located in the same directory as this file.
from testcommon import DEF_DEC
restore_path()
This is basically a hack to put the current path (or any other relative
path you give to set_local_path function) in sys.path so that they are
found by the python interpreter.
cheers,
David
More information about the Scipy-dev
mailing list