10/31/2019 - 2:21 AM

use doc test in python

import doctest


def test_none():
    """
    >>> test_none()
    """
    return None


def test_escape_character():
    r"""
    对于特殊字符,我们可以使用r string的方式
    >>> test_escape_character()
    'a\tb\n'
    """
    return "a\tb\n"


def test_raise():
    """
    ...的意思是ignore中间的字符
    >>> test_raise()
    Traceback (most recent call last):
    ...
    ValueError: wrong
    """
    raise ValueError("wrong")

def test_need_parts_of_lines():
    """
    # doctest:+ELLIPSIS的目的是让...可以匹配任意字符
    >>> test_need_parts_of_lines() # doctest:+ELLIPSIS
    This ... a test
    """
    print("This is a test")
    

if __name__ == "__main__":
    print (doctest.__file__)
    doctest.testmod(verbose=False)