Python doctests: test for None

牧云@^-^@ 提交于 2019-12-04 22:21:05

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

Test for is None instead:

>>> six_or_none(4) is None
True

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!