Web2py 模块和文档测试
我有一个模块 applications/webapp/modules/a.py ,其中包含 local_import 来导入 applications/webapp/modules/b.py 。我想对 a.py 和 b.py 进行文档测试。带有“-T”选项的 web2py shell 部分工作,但在说“在 a.py 中查找测试:class”后,抱怨下面粘贴的异常。
据我所知,这是因为“-T”选项仅用于测试控制器。但由于 a.py 中的 local_import ,没有简单的方法可以在 web2py 环境之外对 a.py 进行文档测试。那么我应该如何重构模块以便我可以对它们进行文档测试呢?
回溯(最近一次调用最后一次):
文件“web2py.py”,第 19 行,位于 gluon.widget.start(cron=True) 文件 “/home/.../web2py/gluon/widget.py”, 第 796 行,开始 测试(options.test, verbose=options.verbose) 文件 “/home/.../web2py/gluon/shell.py”, 第 326 行,测试中 doctest_object(名称, obj) 文件 "/home/.../web2py/gluon/shell.py", 第 322 行,在 doctest_object 中 doctest_object(attr_name, o) 文件 “/home/.../web2py/gluon/shell.py”, 第 321 行,在 doctest_object 中 o = eval('%s.%s' % (name, attr_name), globs) 文件 "", 第 1 行,名称错误:名称 “类”未定义
I have a module applications/webapp/modules/a.py that contains a local_import to import applications/webapp/modules/b.py. I want to doctest a.py and b.py. The web2py shell with "-T" option partially works but complains with the exception pasted below after saying "Finding tests in a.py: class".
I understand that this is because the "-T" option is meant only for testing controllers. But due to local_import within a.py there is no easy way to doctest a.py outside of the web2py environment. So how should I go about refactoring the modules so that I can doctest them?
Traceback (most recent call last):
File "web2py.py", line 19, in
gluon.widget.start(cron=True) File
"/home/.../web2py/gluon/widget.py",
line 796, in start
test(options.test, verbose=options.verbose) File
"/home/.../web2py/gluon/shell.py",
line 326, in test
doctest_object(name, obj) File "/home/.../web2py/gluon/shell.py",
line 322, in doctest_object
doctest_object(attr_name, o) File
"/home/.../web2py/gluon/shell.py",
line 321, in doctest_object
o = eval('%s.%s' % (name, attr_name), globs) File "",
line 1, in NameError: name
'class' is not defined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于这个,我做了如下尝试。目前它工作正常,但不确定这是否是最好的方法。在 private/ 文件夹中,创建一个文件tests.py,其中:
此外,在a.py中,我根据这个。
使用以下命令运行测试:
Based on this, I made an attempt as follows. It works fine as of now but not sure if this is the best approach. In private/ folder, create a file tests.py with:
Moreover, in a.py I used 'import b' instead of 'local_import(b)' as per this.
Run the tests using: