doctests/unittest problem with exception

Discussion in 'Python' started by Paul, Jan 26, 2013.

  1. Paul

    Paul Guest

    Hello. I converted doctests into DocTestSuite() to use with unittest. And try it under Python 3.

    And, sure, I get errors with unmatched exceptions details (mismatched name of exception class: a.b.c.MyError instead of MyError). So, I have 2 questions:

    1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in DocStestSuite (like 'optionflags' argument in doctest.testmod())

    2) Is a way to ignore all 'package path' of exception but not message? Something like:
    ---cut---
    Traceback (most recent call last):
    ...
    ...MyError: 'details are not ignored!'
    ---cut---
    see, ellipsis-prefix in MyError
    Paul, Jan 26, 2013
    #1
    1. Advertising

  2. Paul wrote:

    > Hello. I converted doctests into DocTestSuite() to use with unittest. And
    > try it under Python 3.
    >
    > And, sure, I get errors with unmatched exceptions details (mismatched name
    > of exception class: a.b.c.MyError instead of MyError). So, I have 2
    > questions:
    >
    > 1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in
    > DocStestSuite (like 'optionflags' argument in doctest.testmod())


    Have you tried reading the Fine Manual? If you don't have access to the
    Python documentation

    http://docs.python.org/3/library/doctest.html

    you can get interactive help at the interpreter. Launch the Python
    interactive interpreter, and then give these two commands:

    import doctest
    help(doctest.DocTestSuite)


    In particular, note that DocTestSuite takes a keyword argument:

    optionflags
    A set of doctest option flags expressed as an integer.


    So try passing optionFlags=doctest.IGNORE_EXCEPTION_DETAIL to the
    DocTestSuite.



    > 2) Is a way to ignore all 'package path' of exception but not message?
    > Something like:
    > ---cut---
    > Traceback (most recent call last):
    > ...
    > ...MyError: 'details are not ignored!'
    > ---cut---
    > see, ellipsis-prefix in MyError



    Have you tried it to see? Add this comment to your docstring, following the
    line which causes an exception:

    >>> example() #doctest: +ELLIPSIS

    Traceback (most recent call last):
    ...
    ....MyError: 'details are not ignored!'


    Does that do what you expect?


    --
    Steven
    Steven D'Aprano, Jan 27, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bjorn Tillenius

    unicode in doctests

    Bjorn Tillenius, Nov 29, 2004, in forum: Python
    Replies:
    0
    Views:
    253
    Bjorn Tillenius
    Nov 29, 2004
  2. Thomas Heller

    Running doctests with unittest

    Thomas Heller, Mar 9, 2005, in forum: Python
    Replies:
    1
    Views:
    452
    Jim Sizelove
    Mar 9, 2005
  3. mitchell

    Dynamic doctests?

    mitchell, May 13, 2005, in forum: Python
    Replies:
    1
    Views:
    331
    =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=
    May 13, 2005
  4. John J. Lee
    Replies:
    0
    Views:
    258
    John J. Lee
    May 5, 2006
  5. Paul  Moore
    Replies:
    1
    Views:
    383
    Paul Moore
    Oct 14, 2008
Loading...

Share This Page