diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-09-04 17:21:02 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-09-04 17:21:02 (GMT) |
commit | 1fbf9c5ec10d38d58837e20a681604440aa7b3da (patch) | |
tree | ee3e64b8066a13df7de071bdae9aef0bb4d01f12 /Lib/test | |
parent | ba6019691eddff901bbb7eb5d8a2cc66e5ebaaca (diff) | |
download | cpython-1fbf9c5ec10d38d58837e20a681604440aa7b3da.zip cpython-1fbf9c5ec10d38d58837e20a681604440aa7b3da.tar.gz cpython-1fbf9c5ec10d38d58837e20a681604440aa7b3da.tar.bz2 |
Added IGNORE_EXCEPTION_DETAIL comparison option. The need is explained
in the new docs.
DocTestRunner.__run: Separate the determination of the example outcome
from reporting that outcome, to squash brittle code duplication and
excessive nesting.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_doctest.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 2b39e33..7f51ab5 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -837,6 +837,43 @@ message is raised, then it is reported as a failure: ValueError: message (1, 1) +However, IGNORE_EXCEPTION_DETAIL can be used to allow a mismatch in the +detail: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... Traceback (most recent call last): + ... ValueError: wrong message + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 1) + +But IGNORE_EXCEPTION_DETAIL does not allow a mismatch in the exception type: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... Traceback (most recent call last): + ... TypeError: wrong type + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + Line 2, in f + Failed example: + raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + Expected: + Traceback (most recent call last): + TypeError: wrong type + Got: + Traceback (most recent call last): + ... + ValueError: message + (1, 1) + If an exception is raised but not expected, then it is reported as an unexpected exception: |