我在类方法中有一个带有docstrings的Python模块,并且在模块docstring中有一个真实世界的例子。区别在于方法文档已经被精心制作成完全可重复的测试,而现实世界的例子只是从Linux shell中拷贝历史的一个副本 - 恰巧调用了python解释器。Python doctest:跳过整个块?
E.g.
"""
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的+SKIP
指令只在每行中有效,这意味着要在现实世界中添加10行代码。丑陋!
有没有办法让doctest跳过整个块?有点像<!-- ... -->
在HTML中?
我同意。这是一个非常有用的功能。 – 2009-11-27 15:20:33