Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative results in doctests

Tags:

python

doctest

I have a doctest where I test a float conversion:

>>> float('fish')

In Python < 2.7 this results in:

ValueError: invalid literal for float(): fish

In Python 2.7 the result is

ValueError: could not convert string to float: fish

Can I make both these results acceptable in my doctest?

like image 529
pafcu Avatar asked Jan 05 '11 16:01

pafcu


1 Answers

You are looking for the doctest.IGNORE_EXCEPTION_DETAIL option. The documentation has a good example of how to use it. You can also use the ellipsis constant in the doctest like a wildcard.

Something like this as the doctest:

>>> float('fish')
ValueError:...

You can see Alex Martellis post about this same thing here.

like image 176
Jason Webb Avatar answered Oct 02 '22 23:10

Jason Webb