Doctest w/ docutils¶
Built on doctest.
Run doctests in .rst and .md files via pytest.
Note
Before you begin, acquaint yourself with:
reStructuredText¶
$ python -m doctest_docutils README.rst
That’s what doctest does by design. Pass -v for verbose output.
Markdown¶
If you install [myst-parser], doctest will run on .md files.
$ python -m doctest_docutils README.md
As with the reST example above, no output.
Internals¶
Note
To get a deeper understanding, dig into:
-
All console arguments by seeing the help command:
$ python -m doctest --help
data structures, e.g.
doctest.DocTestsource code: https://github.com/python/cpython/blob/3.11/Lib/doctest.py
documentation: https://docs.python.org/3/library/doctest.html
typings: https://github.com/python/typeshed/blob/master/stdlib/doctest.pyi
docutils: which parses reStructuredText (.rst) and markdown (.md, with the help of [myst-parser])
API¶
Doctest module for docutils.
-
doctest_docutils.is_allowed_version(version, spec)¶
Check spec satisfies version or not.
This obeys PEP-440 specifiers: https://peps.python.org/pep-0440/#version-specifiers
Some examples:
>>> is_allowed_version('3.3', '<=3.5') True >>> is_allowed_version('3.3', '<=3.2') False >>> is_allowed_version('3.3', '>3.2, <4.0') True
-
class doctest_docutils.TestsetupDirective¶
Bases:
TestDirectiveTest setup directive.
-
class doctest_docutils.TestcleanupDirective¶
Bases:
TestDirectiveTest cleanup directive.
-
class doctest_docutils.DoctestDirective¶
Bases:
TestDirectiveDoctest directive.
-
class doctest_docutils.MockTabDirective¶
Bases:
TestDirectiveMock tab directive.
-
doctest_docutils.setup()¶
Configure doctest for doctest_docutils.
-
doctest_docutils._directive_registry()¶
Return docutils directive registry with typing info.
-
doctest_docutils._ensure_directives_registered()¶
Register doctest-related directives once per interpreter.
- Return type:
-
exception doctest_docutils.DocTestFinderNameDoesNotExist¶
Bases:
ValueErrorRaised with doctest lookup name not provided.
-
class doctest_docutils.DocutilsDocTestFinder¶
Bases:
objectDocTestFinder for doctest-docutils.
Class used to extract the DocTests relevant to a docutils file. Doctests are extracted from the following directive types: doctest_block (doctest), DocTestDirective. Myst-parser is also supported for parsing markdown files.
-
exception doctest_docutils.TestDocutilsPackageRelativeError¶
Bases:
ExceptionRaise when doctest_docutils is called for package not relative to module.
-
doctest_docutils.testdocutils(filename, module_relative=True, name=None, package=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, parser=<doctest.DocTestParser object>, encoding=None)¶
Docutils-based test entrypoint.
Based on doctest.testfile at python 3.10
- Parameters:
- Return type: