inveniosoftware / troubleshooting

DEPRECATED - Use the forum instead:
https://invenio-talk.web.cern.ch
5 stars 4 forks source link

`DocTestFailure` when checking exceptions (Python 2 vs 3) #44

Open egabancho opened 5 years ago

egabancho commented 5 years ago

Problem

The doctests succeeds when running on python 2.x, fails when running on python 3.x (or vice versa) and complains when checking an exception. Something similar to this:

>>> Sequence('invalid')
Differences (unified diff with -expected +actual):
    @@ -1,3 +1,10 @@
     Traceback (most recent call last):
    - ...
    -SequenceNotFound
    +  File "/opt/python/3.5.6/lib/python3.5/doctest.py", line 1321, in __run
    +    compileflags, 1), test.globs)
    +  File "<doctest invenio_sequencegenerator[30]>", line 1, in <module>
    +    Sequence('invalid')
    +  File "/home/travis/build/inveniosoftware/invenio-sequencegenerator/invenio_sequencegenerator/api.py", line 61, in __init__
    +    template = Template(template)
    +  File "/home/travis/build/inveniosoftware/invenio-sequencegenerator/invenio_sequencegenerator/api.py", line 31, in __init__
    +    raise SequenceNotFound()
    +invenio_sequencegenerator.errors.SequenceNotFound
/home/travis/build/inveniosoftware/invenio-sequencegenerator/invenio_sequencegenerator/__init__.py:150: DocTestFailure

Solution

Add doctest.IGNORE_EXCEPTION_DETAIL to the doctest. Something similar to this:

>>> Sequence('invalid') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
 ...
invenio_sequencegenerator.errors.SequenceNotFound

Caveats

This will stop checking the exception message, which is part of the test it self, but the exception type is still checked.