Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > doctests/unittest problem with exception

Reply
Thread Tools

doctests/unittest problem with exception

 
 
Paul
Guest
Posts: n/a
 
      01-26-2013
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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      01-27-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 3 06-26-2003 01:02 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 0 06-24-2003 12:46 PM



Advertisments