Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
522fe087
Commit
522fe087
authored
Jul 11, 2003
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document Jim Fulton's docttest extensions.
parent
74e702f6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
8 deletions
+70
-8
Doc/lib/libdoctest.tex
Doc/lib/libdoctest.tex
+70
-8
No files found.
Doc/lib/libdoctest.tex
View file @
522fe087
...
...
@@ -65,7 +65,7 @@ def factorial(n):
raise ValueError("n must be >= 0")
if math.floor(n) != n:
raise ValueError("n must be exact integer")
if n+1 == n: #
e.g.,
1e300
if n+1 == n: #
catch a value like
1e300
raise OverflowError("n too large")
result = 1
factor = 2
...
...
@@ -243,13 +243,75 @@ value of the example).
\subsection
{
Advanced Usage
}
\function
{
testmod()
}
actually creates a local instance of class
\class
{
Tester
}
, runs appropriate methods of that class, and merges
the results into global
\class
{
Tester
}
instance
\code
{
master
}
.
You can create your own instances of
\class
{
Tester
}
, and so build your
own policies, or even run methods of
\code
{
master
}
directly. See
\code
{
Tester.
__
doc
__}
for details.
Several module level functions are available for controlling how doctests
are run.
\begin{funcdesc}
{
debug
}{
module, name
}
Debug a single docstring containing doctests.
Provide the
\var
{
module
}
(or dotted name of the module) containing the
docstring to be debugged and the
\var
{
name
}
(within the module) of the
object with the docstring to be debugged.
The doctest examples are extracted (see function
\function
{
testsource()
}
),
and written to a temporary file. The Python debugger,
\refmodule
{
pdb
}
,
is then invoked on that file.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{funcdesc}
{
testmod
}{}
This function provides the most basic interface to the doctests.
It creates a local instance of class
\class
{
Tester
}
, runs appropriate
methods of that class, and merges the results into the global
\class
{
Tester
}
instance,
\code
{
master
}
.
To get finer control than
\function
{
testmod()
}
offers, create an instance
of
\class
{
Tester
}
with custom policies and run the methods of
\code
{
master
}
directly. See
\code
{
Tester.
__
doc
__}
for details.
\end{funcdesc}
\begin{funcdesc}
{
testsource
}{
module, name
}
Extract the doctest examples from a docstring.
Provide the
\var
{
module
}
(or dotted name of the module) containing the
tests to be extracted and the
\var
{
name
}
(within the module) of the object
with the docstring containing the tests to be extracted.
The doctest examples are returned as a string containing Python
code. The expected output blocks in the examples are converted
to Python comments.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{funcdesc}
{
DocTestSuite
}{
\optional
{
module
}}
Convert doctest tests for a module to a
\refmodule
{
unittest
}
\class
{
TestSuite
}
.
The returned
\class
{
TestSuite
}
is to be run by the unittest framework
and runs each doctest in the module. If any of the doctests fail,
then the synthesized unit test fails, and a
\exception
{
DocTestTestFailure
}
exception is raised showing the name of the file containing the test and a
(sometimes approximate) line number.
The optional
\var
{
module
}
argument provides the module to be tested. It
can be a module object or a (possibly dotted) module name. If not
specified, the module calling
\function
{
DocTestSuite()
}
is used.
Example using one of the many ways that the
\refmodule
{
unittest
}
module
can use a
\class
{
TestSuite
}
:
\begin{verbatim}
import unittest
import doctest
import my
_
module
_
with
_
doctests
suite = doctest.DocTestSuite(my
_
module
_
with
_
doctests)
runner = unittest.TextTestRunner()
runner.run(suite)
\end{verbatim}
\versionadded
{
2.3
}
\end{funcdesc}
\subsection
{
How are Docstring Examples Recognized?
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment