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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With