[Numpy-discussion] Writing successful tests

Robert Kern robert.kern at gmail.com
Mon Apr 14 05:27:27 EDT 2014

On Mon, Apr 14, 2014 at 5:26 AM,  <matt at pagan.io> wrote:
> Greetings,
> I'm working on an additional function for numpy/lib/twodim_base.py. I'm
> trying to add some tests for the new function, and
> numpy/lib/tests/test_twodim_base.py seems like the right place for
> them.
> My problem is travis-ci tells me my tests are no good.
> The error message I get on my local machine is:
> ValueError: no such test method in <class '__main__.TestElementary'>:
> runTest

Please copy-and-paste the whole error message. Can you point to your
code somewhere and the travis-ci results? How are you running the test
suite? `numpy.test()` is the right way to do so. Do not use
`unittest.main()` or `python -m unittest ...` to run the numpy test

> (TestElementary is the class I made to put my tests in).
> This error makes me think I need a to put in a function like
> def __init__(self, methodName="runTest"):
> or maybe
> def runTest(self):
> somewhere. I don't see functions like this associated with any of the
> other classes in numpy/lib/tests/test_twodim_base.py though.

You would never do so, no. numpy uses the `nose` test runner which
does not need these. If you were using the standard unittest test
collector, you would subclass `TestElementary` from
`unittest.TestCase`, and that would provide the correct `__init__()`
and `runTest()` methods.

Robert Kern

More information about the NumPy-Discussion mailing list