42

I'm about to reinstall numpy and scipy on my Ubuntu Lucid. As these things carry quite a few dependencies, I'm wondering if there is a comprehensive test suite to check if the new install really works.

Of course, I can just take a bunch of my scripts and run them one by one to see if they keep working, but that won't guard against a situation where at some point in the future I'll try to use something I didn't use before and it'll break (or, worse, silently produce nonsence).

ev-br
  • 24,968
  • 9
  • 65
  • 78

2 Answers2

58

Yes. Both packages have a test method for this.

import numpy
numpy.test('full')

import scipy
scipy.test('full')

You will need to have pytest and hypothesis installed to run numpy.test.

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52
David Alber
  • 17,624
  • 6
  • 65
  • 71
  • 4
    Alternatively you can run the tests on your command line: ```python -c 'import numpy; numpy.test("full");'``` ```python -c 'import scipy; scipy.test("full");'``` – Darius May 05 '15 at 17:56
  • 3
    it seems that these functions pull in tests from the current directory, so i guess be careful where you call them. – abcd Oct 07 '15 at 18:23
  • 8
    it's also not a good idea to run `numpy.test` followed by `scipy.test` in the same python session. i've had issues with `numpy.test` making global changes to variables that are then picked up by `scipy.test`, causing errors in `scipy.test` that wouldn't otherwise occur: see [this question](http://stackoverflow.com/q/33002730/2623899). – abcd Oct 07 '15 at 22:07
  • It might be worth mentioning that each return a True/False value instead of failing. So when running it in a shell (`python -c`) you might want to check that or have always an exit code of 0 – Flamefire Nov 16 '20 at 13:57
8

Note that binary packages for the mathematical libraries Scipy and Numpy depend on, shipped by Linux distributions, have in some cases showed to be subtly broken. Running Numpy and Scipy test suites with numpy.test() and scipy.test() is recommended, as a first step to confirm that your installation functions properly. If it doesn't, you may want to try another set of binaries if available, or buy some above-mentioned commercial packages.

from http://www.scipy.org/Download

msw
  • 42,753
  • 9
  • 87
  • 112