我在类方法中有一个包含docstrings的Python模块,在模块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
"""
Run Code Online (Sandbox Code Playgroud)
我想运行doctest SomeClass.someMethod,但不是在模块的docstrings中.
Doctest的+SKIP指令仅适用于每行,这意味着在我的真实世界示例中添加10行.丑陋!
有没有办法让doctest跳过整个块?有点像<!-- ... -->HTML?