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


Generic testing tools.


3 Classes


Bases: TestCase

Utility class to create temporary Python/IPython files.

Meant as a mixin class for test cases.

mktmp(src, ext='.py')

Make a valid python temp file.


Hook method for deconstructing the test fixture after testing it.

class, channel='stdout', suppress=True)

Bases: object

Context manager for testing that code prints certain text.


>>> with AssertPrints("abc", suppress=False):
...     print("abcd")
...     print("def")
__init__(s, channel='stdout', suppress=True)
class, channel='stdout', suppress=True)

Bases: AssertPrints

Context manager for checking that certain output isn’t produced.

Counterpart of AssertPrints

13 Functions, files)

Make full paths for all the listed files, based on startPath.

Only the base part of startPath is kept, since this routine is typically used with a script’s __file__ variable as startPath. The base of startPath is then prepended to all the listed files, forming the output list.

  • startPath (string) – Initial path to use as the base for the results. This path is split using os.path.split() and only its first component is kept.

  • files (string or list) – One or more files.


>>> full_path('/foo/',['a.txt','b.txt'])
['/foo/a.txt', '/foo/b.txt']
>>> full_path('/foo',['a.txt','b.txt'])
['/a.txt', '/b.txt']

If a single file is given, the output is still a list:

>>> full_path('/foo','a.txt')

Parse the output of a test run and return errors, failures.


txt (str) –

Text output of a test run, assumed to contain a line of one of the following forms:

'FAILED (errors=1)'
'FAILED (failures=1)'
'FAILED (errors=1, failures=1)'


number of errors and failures.

Return type:

nerr, nfail

Return a valid default argv for creating testing instances of ipython

Return a config object with good defaults for testing.

Return appropriate IPython command line name. By default, this will return a list that can be used with subprocess.Popen, for example, but passing as_string=True allows for returning the IPython command as a string.


as_string (bool) – Flag to allow to return the command as a string., options=None, commands=())

Utility to call ‘ipython filename’.

Starts IPython with a minimal and safe configuration to make startup as fast as possible.

Note that this starts IPython in a subprocess!

  • fname (str, Path) – Name of file to be executed (should have .py or .ipy extension).

  • options (optional, list) – Extra command-line flags to be passed to IPython.

  • commands (optional, list) – Commands to send in on stdin

Return type:

(stdout, stderr) of ipython subprocess., expected_out, expected_err='', options=None, commands=())

Utility to call ‘ipython filename’ and validate output/error.

This function raises an AssertionError if the validation fails.

Note that this starts IPython in a subprocess!

  • fname (str, Path) – Name of the file to be executed (should have .py or .ipy extension).

  • expected_out (str) – Expected stdout of the process.

  • expected_err (optional, str) – Expected stderr of the process.

  • options (optional, list) – Extra command-line flags to be passed to IPython.

Return type:

None, pairs)

Utility function for the common case of checking a function with a sequence of input/output pairs.

  • func (callable) – The function to be tested. Should accept a single argument.

  • pairs (iterable) – A list of (input, expected_output) tuples.


  • None. Raises an AssertionError if any output does not match the expected

  • value.

Create an empty, named, temporary file for the duration of the context.

Temporarily replace the input() function to return the given values

Use as a context manager:

with fake_input([‘result1’, ‘result2’]):

Values are returned in order. If input() is called again after the last value was used, EOFError is raised.'')

test that ipython [subcommand] -h works'')

test that ipython [subcommand] --help-all works