doctests/unittest problem with exception

P

Paul

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
 
S

Steven D'Aprano

Paul said:
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:
Traceback (most recent call last):
...
....MyError: 'details are not ignored!'


Does that do what you expect?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top