Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to doctest an exception ?

I'd like to doctest an exception, to show that some call is expected to fail (and, latter, to show how to cope with that). Something along the lines of:

sage: foo(x)
ValueError
... #Elided
ValueError: x is not palatable to foo

I haven't found any doctest directive allowing me to tell "This test is expected to raise an exception" ; so, when I run the doctest, I can't even compare what I get with the text of the expected traceback. The only solution I found so far is to wrap my test in a try:... except: ... construct, which is not very demonstrative.

Any idea ?