Python Glossary Русский

all Python 3doctestfunction

doctest.debug()

debugging

Runs the doctests of one object in a module under the pdb debugger, selected by a name like 'module.function'.

Syntax

doctest.debug(module, name, pm=False)

It is testsource() plus debug_src(): the docstring becomes a script handed to pdb. The name is the full dotted one ('__main__.f'), otherwise ValueError. Expected output is not checked. Without a terminal (closed stdin) pdb exits at once, so in CI the call does not hang, but it shows nothing either.

Examples

import doctest, io, sys
def area(w, h):
    """
    >>> area(2, 5)
    10
    """
    return w * h
sys.stdin = io.StringIO("next\np area(3, 4)\ncontinue\n")  # команды pdb
doctest.debug(sys.modules["__main__"], "__main__.area")
print("ok")  # → ok — выше pdb напечатал 12

See also

Open in the full glossarydocs.python.orgReport an inaccuracy