我有一個模塊applications/webapp/modules/a.py,其中包含一個local_import來導入applications/webapp/modules/b.py。我想doctest a.py和b.py.具有「-T」選項的web2py外殼部分工作,但在聲明「在a.py中查找測試:類」後粘貼下面的異常。Web2py模塊和Doctests
據我所知,這是因爲「-T」選項僅用於測試控制器。但是由於a.py中的local_import,在web2py環境以外的文檔中測試a.py並不容易。那麼我應該如何去重構模塊以便我可以對它們進行測試呢?
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
此外,由於最近發佈的1.96.x版本,你不再需要local_import在所有使用 - 你可以只使用常規import語句,甚至是從模型和控制器。 – Anthony 2011-06-14 14:30:55
@Anthony非常感謝您提供有用的信息。更多信息:http://groups.google.com/group/web2py/browse_thread/thread/ff3863c566b8b405/b96cd8f3b44e53d6 – 2011-06-15 00:35:36