Basic test writing and execution from within the Python interpreter is
documented in the
NumPy/SciPy testing guidelines. This page
includes information about running tests from the command line using the
spin command line tool. Note: Before beginning, ensure thatpytestis installed.
--help
spin<command-name>--help
spintest--help
To run all tests, navigate to the root SciPy directory at the command
line and execute
spintest
This builds SciPy (or updates an existing build) and runs the tests.
To run tests on a particular submodule, such as optimize, use the
--submodule option:
spintest-soptimize
To run a particular test module, use the Pytest syntax of --test (or
-t):
-v or --verbose, which activates the verbose option for more
detailed output.
-b or --array-api-backendbackend to include alternative
array backends in array-api-compatible tests. See Support for the array API standard
for details.
--coverage to generate a test coverage report in
scipy/build/coverage/index.html. Note:pytest-covmust be
installed.
-n or --no-build to prevent SciPy from updating the build
before testing
-j or --paralleln to engage n cores when building SciPy;
e.g. spintest-j4 engages four cores. As of #10172
this also runs the tests on four cores if pytest-xdist is installed.
-mfull or --modefull to run the “full” test suite, including
tests marked slow (e.g. with @pytest.mark.slow). Note that this
does not run tests marked xslow; see Tips below.
-- to send remaining command line arguments to pytest instead of
spintest. For instance, while -n sent to pytest.py activates
the --no-build option, -n sent to pytest runs the tests on
multiple cores; e.g. spintest---n4 runs tests using
four cores. Note:pytest-xdistmust be installed for testing on
multiple cores. Common command line arguments for include:
For much more information about pytest, see the pytestdocumentation.
Tips:
If you built SciPy from source but are having trouble running tests
after a change to the codebase, try deleting the scipy/build
directory. This forces spin to completely rebuild SciPy before
performing tests.
There is an additional level of very slow tests (several minutes),
which are disabled even when calling spintest-mfull.
They can be enabled by setting the environment variable SCIPY_XSLOW=1
before running the test suite.
By default, tests that use Hypothesis run with the deterministic
profile defined in scipy/scipy/conftest.py. This profile includes the
Hypothesis setting derandomize=True so the same examples are used until
Hypothesis, Python, or the test function are updated. To better use
Hypothesis’ abilities to find counterexamples, select the nondeterministic
profile by setting the environment variable
SCIPY_HYPOTHESIS_PROFILE=nondeterministic before running the test suite.
The number of examples that are run can be configured by editing the selected
configuration, e.g. adding max_examples=100_000.
pytest
--durations=m to display durations of the slowest m tests. Use
--durations=0 together with --durations-min=x to display
durations of all tests with durations that exceed x seconds.
--fail-slow=x to cause test to fail if they exceed x seconds.
(Note: pytest-fail-slow must be installed.)
--timeout=x to halt all test execution if any test time exceeds
x seconds. (Note: pytest-timeout must be installed.)