doctest.script_from_examples
Prev: doctest.run_docstring_examples | Up: doctest | Next: doctest.set_unittest_reportflags
Rel: doctest.debug, doctest.debug_src, doctest.DebugRunner, doctest.DocFileSuite
Ref: docs.python.org — doctest.script_from_examples
Tags: #public #python3 #stdlib #doctest
Import
import doctest
from doctest import script_from_examples
Signature & Overview
doctest.script_from_examples(s)
Extract script from text with examples.
Usage
import doctest
script = doctest.script_from_examples(">>> x = 2\n>>> x * 3\n6\n")
assert "x = 2" in script and "# Expected:" in script
Gotchas
- Turns docstring examples into a runnable Python script with expected outputs as comments.
REPL Inspect
from doctest import script_from_examples
help(script_from_examples)
Linked from
Related notes
- tuts/python3/stdlib_module/doctest/run_docstring_examples Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/set_unittest_reportflags 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/DocTestFinder shared tags: #doctest, #stdlib