10

So, I'm trying to match an exception with a doctest.

>>> api = Api("foo", "bar") # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
AuthError

The issue is that this works with py2.7 but not with python 3. The format of exception trace has been changed so now it include the full module name. I.e. in python 3 I have package.module.AuthError instead.

Is there a way to match both? Seems like IGNORE_EXCEPTION_DETAIL has no effect here.

Nikolay Derkach
  • 1,734
  • 2
  • 22
  • 34

1 Answers1

9

This was unintentionally broken by a patch for a related issue: IGNORE_EXCEPTION_DETAIL should ignore the module name

and the unintended behavior you're seeing is an open issue here: doctest.IGNORE_EXCEPTION_DETAIL doesn't match when no detail exists

So it's a bug, according to me. Which is pretty good assurance it will get fixed, since I wrote doctest to begin with ;-) In the meantime, you may want to try the patch attached to the 2nd bug report.

Followup: Last night I checked in a fix for this, which will appear in the next releases of Pythons 2.7, 3.3, and 3.4. Thanks for the nudge :-)

Tim Peters
  • 67,464
  • 13
  • 126
  • 132
  • Isn't a `doctest:` prefix required in the comment? Or are these just redundant? At least they are included in all examples here: http://docs.python.org/3.2/library/doctest.html#doctest.IGNORE_EXCEPTION_DETAIL – Robert Jørgensgaard Engdahl Dec 03 '13 at 20:22
  • @RobertJørgensgaardEngdahl, yes, `doctest:` is required. I skipped over that because it wasn't the real point of Nikolay's question - the behavior he described obtains even if the directive is spelled correctly ;-) – Tim Peters Dec 03 '13 at 20:33