相关疑难解决方法(0)

Doctest用于嵌套docstring

假设我有以下代码:

def foo(s):
    """A dummy function foo. For example:

>>> a = '''This is a test string line 1
This is a test string line 2
This is a test string line 3'''
>>> foo(a)
This is a test string line 1
This is a test string line 2
This is a test string line 3
>>>
    """
    print s

if __name__ == '__main__':
    import doctest
    doctest.testmod()
Run Code Online (Sandbox Code Playgroud)

让我们把它保存为foo.py. 当我跑:

C:\Python27>python.exe foo.py
**********************************************************************
File "foo.py", line 5, in __main__.foo
Failed example: …
Run Code Online (Sandbox Code Playgroud)

python doctest docstring

6
推荐指数
1
解决办法
770
查看次数

标签 统计

docstring ×1

doctest ×1

python ×1