Title: doctest.IGNORE_EXCEPTION_DETAIL doesn't match when no detail exists
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.3, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: jamur2, python-dev, tim.peters
Priority: normal Keywords: patch

Created on 2013-10-01 15:54 by jamur2, last changed 2013-12-04 03:30 by python-dev. This issue is now closed.

File name Uploaded Description Edit
exception_normalize.patch jamur2, 2013-10-01 15:54 Test demonstrating issue, and naive fix review
Messages (6)
msg198792 - (view) Author: John Murphy (jamur2) Date: 2013-10-01 15:54
The doctest.IGNORE_EXCEPTION_DETAIL optionflag does not seem to have the
desired behavior when the exception does not provide a message, due to the
regular expressions in doctest.DocTestRunner.__run expecting a colon in the
second group::

                elif self.optionflags & IGNORE_EXCEPTION_DETAIL:
                    m1 = re.match(r'(?:[^:]*\.)?([^:]*:)', example.exc_msg)
                    m2 = re.match(r'(?:[^:]*\.)?([^:]*:)', exc_msg)
                    if m1 and m2 and check(,,
                        outcome = SUCCESS

Normally this wouldn't matter, as there's no need to ignore the exception
detail if there is no detail to normalize, but since it looks like the blessed method of
normalizing Python 2 and 3 exceptions in doctests is to use
IGNORE_EXCEPTION_DETAIL.  This doesn't work for any exceptions which do
not have a message.


    >>> def f(x):
    ...     r'''
    ...     >>> from http.client import HTTPException
    ...     >>> raise HTTPException() #doctest: +IGNORE_EXCEPTION_DETAIL
    ...     Traceback (most recent call last):
    ...     '''
    >>> test = doctest.DocTestFinder().find(f)[0]
    >>> doctest.DocTestRunner(verbose=True).run(test)
    Failed example:
        raise HTTPException() #doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        Traceback (most recent call last):

I've attached a test and a very naive fix of the regular expression.
msg205144 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2013-12-03 20:15
I agree this is a bug, and at a first scan your fix looks good.  I'll make it a priority to pay more attention to it now ;-)
msg205164 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2013-12-03 22:41
On second thought, I don't want to use a regexp for this.  The mandatory colon _was_ a kind of absolute wall, and the various instances of "[^:]" exploited that to avoid unintended matches.

But "possibly dotted name followed possibly by a colon" is straightforward to get right with a pair of simple string searches, so I'll introduce a new `_strip_exception_details()` function instead.
msg205191 - (view) Author: Roundup Robot (python-dev) Date: 2013-12-04 03:02
New changeset c80083ad142d by Tim Peters in branch 'default':
Issue #19138: doctest's IGNORE_EXCEPTION_DETAIL now allows no detail at all.
msg205192 - (view) Author: Roundup Robot (python-dev) Date: 2013-12-04 03:21
New changeset 5e14a3435f52 by Tim Peters in branch '2.7':
Issue #19138: doctest's IGNORE_EXCEPTION_DETAIL now allows no detail at all.
msg205193 - (view) Author: Roundup Robot (python-dev) Date: 2013-12-04 03:30
New changeset 017d7c27a4f6 by Tim Peters in branch '3.3':
Issue #19138: doctest's IGNORE_EXCEPTION_DETAIL now allows no detail at all.
Date User Action Args
2013-12-04 03:30:52python-devsetmessages: + msg205193
2013-12-04 03:24:21tim.peterssetstatus: open -> closed
resolution: fixed
stage: resolved
2013-12-04 03:21:39python-devsetmessages: + msg205192
2013-12-04 03:02:19python-devsetnosy: + python-dev
messages: + msg205191
2013-12-03 22:41:48tim.peterssetmessages: + msg205164
2013-12-03 20:15:19tim.peterssetassignee: tim.peters
messages: + msg205144
2013-10-14 14:54:39georg.brandlsetnosy: + tim.peters
2013-10-01 15:54:51jamur2create