[issue19138] doctest.IGNORE_EXCEPTION_DETAIL doesn't match when no detail exists

John Murphy report at bugs.python.org
Tue Oct 1 17:54:51 CEST 2013


New submission from John Murphy:

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(m1.group(1), m2.group(1),
                                           self.optionflags):
                        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
http://bugs.python.org/issue7490 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.

Example::

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

I've attached a test and a very naive fix of the regular expression.

----------
components: Tests
files: exception_normalize.patch
keywords: patch
messages: 198792
nosy: jamur2
priority: normal
severity: normal
status: open
title: doctest.IGNORE_EXCEPTION_DETAIL doesn't match when no detail exists
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file31936/exception_normalize.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19138>
_______________________________________


More information about the Python-bugs-list mailing list