This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: testing.decorators

Decorators for labeling test objects.

Decorators that merely return a modified version of the original function object are straightforward. Decorators that return a new function object need to use in returning the decorator, in order to preserve metadata such as function name, setup and teardown functions and so on - see for more information.

This module provides a set of useful decorators meant to be ready to use in your own tests. See the bottom of the file for the ready-made ones, and if you find yourself writing a new one that may be of generic use, add it here.

Included decorators:

Lightweight testing that remains unittest-compatible.

  • An @as_unittest decorator can be used to tag any normal parameter-less function as a unittest TestCase. Then, both nose and normal unittest will recognize it as such. This will make it easier to migrate away from Nose if we ever need/want to while maintaining very lightweight tests.

NOTE: This file contains IPython-specific decorators. Using the machinery in IPython.external.decorators, we import either numpy.testing.decorators if numpy is available, OR use equivalent code in IPython.external._decorators, which we’ve copied verbatim from numpy.

6 Functions


Decorator to make a simple function into a normal test via unittest.

IPython.testing.decorators.skipif(skip_condition, msg=None)

Make function raise SkipTest exception if skip_condition is true

  • skip_condition (bool or callable) – Flag to determine whether to skip test. If the condition is a callable, it is used at runtime to dynamically make the decision. This is useful for tests that may require costly imports, to delay the cost until the test suite is actually executed.

  • msg (string) – Message to give on raising a SkipTest exception.


decorator – Decorator, which, when applied to a function, causes SkipTest to be raised when the skip_condition was True, and the function to be called normally otherwise.

Return type:



Decorator factory - mark a test function for skipping from test suite.


msg (string) – Optional message to be added.


decorator – Decorator, which, when applied to a function, causes SkipTest to be raised, with the optional message added.

Return type:


IPython.testing.decorators.onlyif(condition, msg)

The reverse from skipif, see skipif for details.


Can module be imported? Returns true if module does NOT import.

This is used to make a decorator to skip tests that require module to be available, but delay the ‘import numpy’ to test execution time.


Decorator to skip test when at least one of commands is not found.