mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Only recognize the expected output as an exception if it *starts* with
a traceback message. I.e., examples that raise exceptions may no longer generate pre-exception output. This restores the behavior of doctest in python 2.3. The ability to check pre-exception output is being removed because it makes the documentation simpler; and because there are very few use cases for it.
This commit is contained in:
parent
d2afee47b1
commit
19b1958730
3 changed files with 55 additions and 54 deletions
|
@ -623,8 +623,10 @@ replaced with any other string:
|
|||
>>> doctest.DocTestRunner(verbose=False).run(test)
|
||||
(0, 2)
|
||||
|
||||
An example may generate output before it raises an exception; if it
|
||||
does, then the output must match the expected output:
|
||||
An example may not generate output before it raises an exception; if
|
||||
it does, then the traceback message will not be recognized as
|
||||
signaling an expected exception, so the example will be reported as an
|
||||
unexpected exception:
|
||||
|
||||
>>> def f(x):
|
||||
... '''
|
||||
|
@ -636,7 +638,15 @@ does, then the output must match the expected output:
|
|||
... '''
|
||||
>>> test = doctest.DocTestFinder().find(f)[0]
|
||||
>>> doctest.DocTestRunner(verbose=False).run(test)
|
||||
(0, 2)
|
||||
... # doctest: +ELLIPSIS
|
||||
**********************************************************************
|
||||
Line 3, in f
|
||||
Failed example:
|
||||
print 'pre-exception output', x/0
|
||||
Exception raised:
|
||||
...
|
||||
ZeroDivisionError: integer division or modulo by zero
|
||||
(1, 2)
|
||||
|
||||
Exception messages may contain newlines:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue