Conditional tests for test classes derived from NumpyTest

pearu at cens.ioc.ee pearu at cens.ioc.ee
Thu Oct 19 05:33:43 CDT 2006


On Thu, 19 Oct 2006, David Cournapeau wrote:

> Hi,
> 
>     Is there a simple way to execute tests inherited from NumpyTest 
> conditionally ? I have something like that for now:
> 
>     class test_c_implementation(NumpyTestCase):
>         def _check(self, level, decimal = 12):
>             try:
>                 from foo import bar
>                 Y   = bar()
>             except ImportError, inst:
>                 print "Error while importing bar, not tested"
>                 print " -> (Import error was %s)" % inst
> 
>     And all checking functions of the class call _check. The problem is 
> that if there are 10 check functions, there are 10 errors reported, 
> which is a bit stupid,

One approach is demonstrated in scipy/Lib/lib/blas/tests/test_fblas.py.
In your case:

class base_test_c_implementation:
    def check_bar(self, level, decimal=12):
        Y = bar()

try:
    from foo import bar
    class test_c_implementation(base_test_c_implementation,NumpyTestCase):
        pass
except ImportError, inst:
    print "Error while importing bar, not tested"
    print " -> (Import error was %s)" % inst


Pearu


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list