Python doctests: test for None Python doctests: test for None python python

Python doctests: test for None


The Python interpreter ignores None return values, so doctests do the same.

Test for is None instead:

>>> six_or_none(4) is NoneTrue


Other option would be a direct check for None:

def six_or_none(val):    """    >>> six_or_none(6)    6    >>> six_or_none(4)    """    if val == 6:        return 6    return None


Another alternative if you want something that looks like you might expect in your docs is:

>>> print(six_or_none(4))None