Search code examples
pythonpython-2.6pypydoctest

Doctest succeeds in Python v2.7 but not with Python 2.6 due to inconsistent error message


I have coded up some doc test cases in my code comments and put them under travis-ci to run against Python v2.6, v2.7 and Pypy. Only v2.7 succeeded.

My doctest looks like the following::

>>> a = ['a', 'b']
>>> a.index('i')
Traceback (most recent call last):
...
ValueError: 'i' is not in list

Python v2.6 and Pypy both complained that the error return were:

ValueError: list.index(x): x not in list

Is there a better way of testing it than simply deleting these test cases?

Thanks

chfw


Solution

  • Have you tried using ELLIPSIS like this:

    >>> a = ['a', 'b']
    >>> a.index('i') # doctest:+ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: ...