Important

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.ipunittest

Experimental code for cleaner support of IPython syntax with unittest.

In IPython up until 0.10, we’ve used very hacked up nose machinery for running tests with IPython special syntax, and this has proved to be extremely slow. This module provides decorators to try a different approach, stemming from a conversation Brian and I (FP) had about this problem Sept/09.

The goal is to be able to easily write simple functions that can be seen by unittest as tests, and ultimately for these to support doctests with full IPython syntax. Nose already offers this based on naming conventions and our hackish plugins, but we are seeking to move away from nose dependencies if possible.

This module follows a different approach, based on decorators.

  • A decorator called @ipdoctest can mark any function as having a docstring that should be viewed as a doctest, but after syntax conversion.

Authors

2 Classes

class IPython.testing.ipunittest.IPython2PythonConverter

Bases: object

Convert IPython ‘syntax’ to valid Python.

Eventually this code may grow to be the full IPython syntax conversion implementation, but for now it only does prompt conversion.

__init__()
class IPython.testing.ipunittest.Doc2UnitTester(verbose=False)

Bases: object

Class whose instances act as a decorator for docstring testing.

In practice we’re only likely to need one instance ever, made below (though no attempt is made at turning it into a singleton, there is no need for that).

__init__(verbose=False)

New decorator.

Parameters:

verbose (boolean, optional (False)) – Passed to the doctest finder and runner to control verbosity.

2 Functions

IPython.testing.ipunittest.count_failures(runner)

Count number of failures in a doctest runner.

Code modeled after the summarize() method in doctest.

IPython.testing.ipunittest.ipdocstring(func)

Change the function docstring via ip2py.