【发布时间】:2009-11-27 14:17:13
【问题描述】:
我在类方法中有一个带有文档字符串的 Python 模块,在模块文档字符串中有一个真实示例。区别在于方法文档字符串经过精心设计,可以完全重复测试,而真实世界的示例只是 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,但不在模块的文档字符串中。
Doctest 的 +SKIP 指令仅适用于每行,这意味着在我的真实示例中添加 10 行。丑!
有没有办法让 doctest 跳过整个块?有点像 HTML 中的<!-- ... -->?
【问题讨论】: