doctest 本地定义的函数
有什么方法可以对本地定义的函数进行文档测试吗?举个例子,我不想
def foo():
""" >>> foo()
testfoo"""
def foo2():
""" >>> 1/0 """
print 'testfoo'
foo2()
通过测试。但我仍然不想让 foo2 成为整个模块的全局...
is there any way to doctest locally defined functions? As an example I would want
def foo():
""" >>> foo()
testfoo"""
def foo2():
""" >>> 1/0 """
print 'testfoo'
foo2()
to NOT pass the test. But still I would not want to make foo2 global for the entire module...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢。我已经担心在文档字符串之外无法绕过代码。尽管如此,我仍然认为可能有一个技巧可以导入函数的局部变量,从而访问嵌套函数。无论如何,使用 Alex 方法的解决方案将是“
现在唯一的问题是如何自动化这种方法,因此有类似
但没有导入和内置函数和变量的东西。
Thanks. I already feared there would be no way around code outside the docstring. Still I thought there might be a trick to import the locals of a function and thus get access to nested functions. Anyhow, a solution using Alex' approach would read
Now the only question is how to automate this approach, so one has something like
but without the imported and built in functions and variables.
你只是遇到了一个空格问题——如果你修复它,例如如下:
测试就很好地通过了。
You just have a whitespace problem -- if you fix it, for example as follows:
the test passes just fine.