On this page
doctest.DocTestParser
Prev: doctest.DocTestFinder | Up: doctest | Next: doctest.DocTestRunner
Rel: doctest.debug, doctest.debug_src, doctest.DebugRunner, doctest.DocFileSuite
Ref: docs.python.org — doctest.DocTestParser
Tags: #public #python3 #stdlib #doctest
Import
import doctest
from doctest import DocTestParser
Signature & Overview
doctest.DocTestParser()
A class used to parse strings containing doctest examples.
Methods & Attributes
DocTestParser.get_doctest(self, string, globs, name, filename, lineno)— Extract all doctest examples from the given string, and collect them into aDocTestobject.DocTestParser.get_examples(self, string, name='<string>')— Extract all doctest examples from the given string, and return them as a list ofExampleobjects. Line numbers are 0-based, because it's most common in doctests that nothingDocTestParser.parse(self, string, name='<string>')— Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings.
Usage
import doctest
examples = doctest.DocTestParser().get_examples(">>> 2 * 3\n6\n")
assert len(examples) == 1 and examples[0].want == "6\n"
Gotchas
- Extracts
Exampleobjects from any string without executing them.
REPL Inspect
from doctest import DocTestParser
help(DocTestParser)
Linked from
Related notes
- tuts/python3/stdlib_module/doctest/DocTestFinder Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestRunner Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug_src Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DebugRunner Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocFileSuite Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTest Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/doctest/DocTestFailure shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestSuite shared tags: #doctest, #stdlib