Are portable doctests for python 2 / python 3 possible?

Viewed 342
def fib_r(n, memo={0: 0, 1: 1}):
    """recursive fibonacci numbers generation with memoisation

    >>> [fib_r(n) for n in range(10)]
    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
    >>> fib_r(100)
    354224848179261915075"""
    if n not in memo:
        memo[n] = fib(n - 1) + fib(n - 2)
    return memo[n]

The doctest above passes on python 3 but fails on 2.x like this:

**********************************************************************
File "euler.py", line 93, in __main__.fib
Failed example:
    fib_r(100)
Expected:
    354224848179261915075
Got:
    354224848179261915075L

This is just an example, I have seen this in several other situations (e.g. whether a unicode string has an u prefix or not). I was wondering if there is an option for doctest to ignore trivial differences between python 2 and 3 like this?

I am not looking for a workaround to modify the test itself so that it works despite the limitation. I just want to know if there is a flag or something to allow some lenience for compatibility with these minor things that have changed in python versions.

1 Answers
Related