Test support — NumPy v2.6.dev0 Manual

Common test support for all numpy test scripts.

This single module should provide all the common functionality for numpy tests in a single location, so that

test scripts

can just import it and work right away. For background, see the

Testing guidelines

Asserts

#

assert_allclose

(actual, desired[, rtol, ...])

Raises an AssertionError if two objects are not equal up to desired tolerance.

assert_array_almost_equal_nulp

(x, y[, nulp])

Compare two arrays relatively to their spacing.

assert_array_max_ulp

(a, b[, maxulp, dtype])

Check that all items of arrays differ in at most N Units in the Last Place.

assert_array_equal

(actual, desired[, ...])

Raises an AssertionError if two array_like objects are not equal.

assert_array_less

(x, y[, err_msg, verbose, ...])

Raises an AssertionError if two array_like objects are not ordered by less than.

assert_equal

(actual, desired[, err_msg, ...])

Raises an AssertionError if two objects are not equal.

assert_raises

(assert_raises)

Fail unless an exception of class exception_class is thrown by callable when invoked with arguments args and keyword arguments kwargs.

assert_raises_regex

(exception_class, ...)

Fail unless an exception of class exception_class and with message that matches expected_regexp is thrown by callable when invoked with arguments args and keyword arguments kwargs.

assert_warns

(warning_class, *args, **kwargs)

Fail unless the given callable throws the specified warning.

assert_no_warnings

(*args, **kwargs)

Fail if the given callable produces any warnings.

assert_no_gc_cycles

(*args, **kwargs)

Fail if the given callable produces any reference cycles.

assert_string_equal

(actual, desired)

Test if two strings are equal.

Asserts (not recommended)

#

It is recommended to use one of

assert_allclose

,

assert_array_almost_equal_nulp

or

assert_array_max_ulp

instead of these functions for more consistent floating point comparisons.

Decorators

#

Test running

#

Testing custom array containers (

numpy.testing.overrides

)

#

These functions can be useful when testing custom array container implementations which make use of __array_ufunc__/__array_function__.

Guidelines

#

Testing guidelines

Introduction

Testing NumPy

Running tests from inside Python

Running tests from the command line

Running tests in multiple threads

Running doctests

Other methods of running tests

Writing your own tests

Using C code in tests

build_and_import_extension

Labeling tests

Setup and teardown methods

Parametric tests

Doctests

tests/

__init__.py and setup.py

Tips & Tricks

Known failures & skipping tests

Tests on random data

Writing thread-safe tests

Documentation for numpy.test

test