# Test Support (`numpy.testing`)

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`(x, y[, err_msg, verbose]) | 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, verbose]) | 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_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.

`assert_almost_equal`(actual, desired[, ...]) | Raises an AssertionError if two items are not equal up to desired precision.
`assert_approx_equal`(actual, desired[, ...]) | Raises an AssertionError if two items are not equal up to significant digits.
`assert_array_almost_equal`(x, y[, decimal, ...]) | Raises an AssertionError if two objects are not equal up to desired precision.

## Decorators

`dec.deprecated`([conditional]) | Deprecated since version 1.21.
`dec.knownfailureif`(fail_condition[, msg]) | Deprecated since version 1.21.
`dec.setastest`([tf]) | Deprecated since version 1.21.
`dec.skipif`(skip_condition[, msg]) | Deprecated since version 1.21.
`dec.slow`(t) | Deprecated since version 1.21.
`decorate_methods`(cls, decorator[, testmatch]) | Apply a decorator to all methods in a class matching a regular expression.

## Test Running

`Tester` | alias of `numpy.testing._private.nosetester.NoseTester`
`run_module_suite`([file_to_run, argv]) | Run a test module.
`rundocs`([filename, raise_on_error]) | Run doctests found in the given file.
`suppress_warnings`([forwarding_rule]) | Context manager and decorator doing much the same as `warnings.catch_warnings`.

## Guidelines

- Testing Guidelines
  - Introduction
  - Testing NumPy
    - Running tests from inside Python
    - Running tests from the command line
    - Other methods of running tests
  - Writing your own tests
    - Using C code in tests
    - Labeling tests
    - Easier setup and teardown functions / methods
    - Parametric tests
    - Doctests
    - `tests/`
    - `__init__.py` and `setup.py`
  - Tips & Tricks
    - Creating many similar tests
    - Known failures & skipping tests
    - Tests on random data
    - Documentation for `numpy.test`

previous

numpy.digitize

next

numpy.testing.assert_allclose