Python doctest:跳过整个块?
发布时间:2020-05-27 19:50:08 所属栏目:Python 来源:互联网
导读:我有一个 Python模块,在类方法中使用docstrings,在模块docstring中有一个现实的例子.区别在于方法 – 文档格式被精心制作为完全可重复的测试,而现实世界的例子只是一个从Linux shell的历史的拷贝 – 这恰恰是调用python解释器. 例如. Real-world example:# py
|
我有一个 Python模块,在类方法中使用docstrings,在模块docstring中有一个现实的例子.区别在于方法 – 文档格式被精心制作为完全可重复的测试,而现实世界的例子只是一个从Linux shell的历史的拷贝 – 这恰恰是调用python解释器. 例如. """
Real-world example:
# python2.5
Python 2.5 (release25-maint,Jul 20 2008,20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> from packagename import module
>>> module.show_real_world_usage()
'Hello world!'
"""
class SomeClass(object):
def someMethod(self):
"""
>>> 1 == 1
True
"""
我想在SomeClass.someMethod中运行doctest,但不要在模块的docstrings中运行. Doctest的SKIP指令只适用于每行,这意味着将10条线添加到我的现实世界中.丑陋! 有没有办法使doctest跳过整个块?有点像<! - ... - >在HTML中? 解决方法将示例包含在函数中,然后跳过函数调用:""" >>> def example(): >>> from packagename import module >>> module.show_real_world_usage() >>> example() # doctest: +SKIP 'Hello world!' """ (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
