Open Table Of Contents

Using doctest with Numba

Numba allows numba functions decorated with jit or autojit to participate in doctest modules. Instead of using the doctest module, one has to use numba.testmod instead:

import numba

@numba.autojit
def func(value):
    """
    >>> func(10.0)
    10.0
    """
    return value

numba.testmod()
numba.testmod(module=None, run=True, optionflags=0, verbosity=2)
Parameters:
  • module – python module to process for doctest functions
  • run – whether to run the doctests or only build the module.__test__ dict
  • optionflags – doctest options (e.g. doctest.ELLIPSIS)
  • verbosity – verbosity level passed to unittest.TextTestRunner