bundles / scipy 1.17.1 / docs
Doc
Running SciPy Tests Locally
docs/dev:contributor:devpy_test
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 that |pytest|_ is installed.
To run all tests, navigate to the root SciPy directory at the command line and execute
spin testThis 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:
spin test -s optimizeTo run a particular test module, use the Pytest syntax of --test (or -t)
spin test -t scipy.<module>.tests.<test_file>Example for |test-linprog|_ file tests, run:
spin test -t scipy.optimize.tests.test_linprogTo run a test class:
spin test -t scipy.<module>.tests.<test_file>::<TestClass>Example for TestLinprogRSCommon class from test_linprog.py:
spin test -t scipy.optimize.tests.test_linprog::TestLinprogRSCommonTo run a particular test:
spin test -t scipy.<module>.tests.<test_file>::<test_name>Example for test_unknown_solvers_and_options from test_linprog.py:
spin test -t scipy.optimize.tests.test_linprog::test_unknown_solvers_and_optionsFor tests within a class, you need to specify the class name and the test name:
spin test -t scipy.<module>.tests.<test_file>::<TestClass>::<test_name>Example:
spin test -t scipy.optimize.tests.test_linprog::TestLinprogRSCommon::test_nontrivial_problem_with_guessOther useful options include:
-vor--verbose, which activates the verbose option for more detailed output.-bor--array-api-backendbackend to include alternative array backends in array-api-compatible tests. See dev-arrayapi for details.--coverageto generate a test coverage report inscipy/build/coverage/index.html. Note: |pytest-cov|_ must be installed.-nor--no-buildto prevent SciPy from updating the build before testing-jor--paralleln to engage n cores when building SciPy; e.g.spin test -j 4engages four cores. As of #10172 this also runs the tests on four cores if |pytest-xdist|_ is installed.-m fullor--mode fullto run the "full" test suite, including tests markedslow(e.g. with@pytest.mark.slow). Note that this does not run tests markedxslow; see Tips below.--to send remaining command line arguments topytestinstead ofspin test. For instance, while-nsent topytest.pyactivates the--no-buildoption,-nsent topytestruns the tests on multiple cores; e.g.spin test -- -n 4runs tests using four cores. Note: |pytest-xdist|_ must be installed for testing on multiple cores. Common command line arguments forpytestinclude:--durations=mto display durations of the slowestmtests. Use--durations=0together with--durations-min=xto display durations of all tests with durations that exceedxseconds.--fail-slow=xto cause test to fail if they exceedxseconds. (Note: |pytest-fail-slow|_ must be installed.)--timeout=xto halt all test execution if any test time exceedsxseconds. (Note: |pytest-timeout|_ must be installed.)
For much more information about pytest, see the pytest documentation.
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 spin test -m full. 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.