This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Created on 2013-10-01 15:54 by jamur2, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
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(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.
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) (Python triager) 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. http://hg.python.org/cpython/rev/c80083ad142d
msg205192 - (view) Author: Roundup Robot (python-dev) (Python triager) 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. http://hg.python.org/cpython/rev/5e14a3435f52
msg205193 - (view) Author: Roundup Robot (python-dev) (Python triager) 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. http://hg.python.org/cpython/rev/017d7c27a4f6
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63337
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