_pytest.doctest module

discover and run doctests in modules and test files.

pytest_addoption(parser)[source]
pytest_unconfigure()[source]
pytest_collect_file(path, parent)[source]
_is_setup_py(config, path, parent)[source]
_is_doctest(config, path, parent)[source]
class ReprFailDoctest(reprlocation_lines: Sequence[Tuple[_pytest._code.code.ReprFileLocation, Sequence[str]]])[source]

Bases: _pytest._code.code.TerminalRepr

toterminal(tw: _pytest._io.TerminalWriter)None[source]
exception MultipleDoctestFailures(failures)[source]

Bases: Exception

_init_runner_class() → Type[doctest.DocTestRunner][source]
_get_runner(checker: Optional[doctest.OutputChecker] = None, verbose: Optional[bool] = None, optionflags: int = 0, continue_on_failure: bool = True)doctest.DocTestRunner[source]
class DoctestItem(*k, **kw)[source]

Bases: _pytest.nodes.Item

classmethod from_parent(parent: Union[_pytest.doctest.DoctestTextfile, _pytest.doctest.DoctestModule], *, name, runner, dtest)[source]

the public named constructor

setup()[source]
runtest()None[source]
_disable_output_capturing_for_darwin()[source]

Disable output capturing. Otherwise, stdout is lost to doctest (#985)

repr_failure(excinfo)[source]
reportinfo() → Tuple[py._path.local.LocalPath, int, str][source]
_get_flag_lookup() → Dict[str, int][source]
get_optionflags(parent)[source]
_get_continue_on_failure(config)[source]
class DoctestTextfile(*k, **kw)[source]

Bases: _pytest.python.Module

obj = None
for ... in collect()[source]

returns a list of children (items and collectors) for this collection node.

_check_all_skipped(test)[source]

raises pytest.skip() if all examples in the given DocTest have the SKIP option set.

_is_mocked(obj)[source]

returns if a object is possibly a mock object by checking the existence of a highly improbable attribute

with _patch_unwrap_mock_aware()[source]

contextmanager which replaces inspect.unwrap with a version that’s aware of mock objects and doesn’t recurse on them

class DoctestModule(*k, **kw)[source]

Bases: _pytest.python.Module

for ... in collect()[source]

returns a list of children (items and collectors) for this collection node.

_setup_fixtures(doctest_item)[source]

Used by DoctestTextfile and DoctestItem to setup fixture information.

_init_checker_class() → Type[doctest.OutputChecker][source]
_get_checker()doctest.OutputChecker[source]

Returns a doctest.OutputChecker subclass that supports some additional options:

  • ALLOW_UNICODE and ALLOW_BYTES options to ignore u’’ and b’’ prefixes (respectively) in string literals. Useful when the same doctest should run in Python 2 and Python 3.

  • NUMBER to ignore floating-point differences smaller than the precision of the literal number in the doctest.

An inner class is used to avoid importing “doctest” at the module level.

_get_allow_unicode_flag()int[source]

Registers and returns the ALLOW_UNICODE flag.

_get_allow_bytes_flag()int[source]

Registers and returns the ALLOW_BYTES flag.

_get_number_flag()int[source]

Registers and returns the NUMBER flag.

_get_report_choice(key: str)int[source]

This function returns the actual doctest module flag value, we want to do it as late as possible to avoid importing doctest and all its dependencies when parsing options, as it adds overhead and breaks tests.

doctest_namespace()[source]

Fixture that returns a dict that will be injected into the namespace of doctests.