PyDocs

Nav

Development Tools

Example

doctest

class (source)
  • Example(source, want, exc_msg=None, lineno=0, indent=0, options=None)
A single doctest example, consisting of source code and expected
output.  `Example` defines the following attributes:

  - source: A single Python statement, always ending with a newline.
    The constructor adds a newline if needed.

  - want: The expected output from running the source code (either
    from stdout, or a traceback in case of exception).  `want` ends
    with a newline unless it's empty, in which case it's an empty
    string.  The constructor adds a newline if needed.

  - exc_msg: The exception message generated by the example, if
    the example is expected to generate an exception; or `None` if
    it is not expected to generate an exception.  This exception
    message is compared against the return value of
    `traceback.format_exception_only()`.  `exc_msg` ends with a
    newline unless it's `None`.  The constructor adds a newline
    if needed.

  - lineno: The line number within the DocTest string containing
    this Example where the Example begins.  This line number is
    zero-based, with respect to the beginning of the DocTest.

  - indent: The example's indentation in the DocTest string.
    I.e., the number of space characters that precede the
    example's first prompt.

  - options: A dictionary mapping from option flags to True or
    False, which is used to override default options for this
    example.  Any option flags not contained in this dictionary
    are left at their default value (as specified by the
    DocTestRunner's optionflags).  By default, no options are set.
Members of Example

e

exc_msg
The exception message generated by the example, if the example is expected to generate an exception; or None if it is not expected to generate an exception.

i

indent
The example’s indentation in the containing string, i.e., the number of space characters that precede the example’s first prompt.

l

lineno
The line number within the string containing this example where the example begins.

o

options
A dictionary mapping from option flags to True or False, which is used to override default options for this example.

s

source
A string containing the example’s source code.

w

want
The expected output from running the example’s source code (either from stdout, or a traceback in case of exception).
0 Examples
No examples for doctest/Example.
See Also
No see-alsos for doctest/Example
0 Notes
No notes for Example