我无法理解这个错误:
======================================================================
ERROR: test_webtest (unittest2.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_webtest
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/unittest2/loader.py", line 260, in _find_tests
module = self._get_module_from_name(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/unittest2/loader.py", line 238, in _get_module_from_name
__import__(name)
File "/Users/chris/Documents/gae/tasker/test/test_webtest.py", line 4, in <module>
import webtest
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/webtest/__init__.py", line 9, in <module>
from webtest.app import TestApp
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/webtest/app.py", line 65, in <module>
class TestRequest(webob.BaseRequest):
AttributeError: 'module' object has no attribute 'BaseRequest'
情况是:
我正在使用此命令从终端运行测试:
./run_tests.py /usr/local/google_appengine test/
我正在使用this tutorial来构建我的处理程序测试。但它永远不会超过进口。我所要做的就是在test/test_webtest.py
中生成错误:
import webtest
我安装了webtest:
$ pip install WebTest
Requirement already satisfied (use --upgrade to upgrade): WebTest in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): six in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from WebTest)
Requirement already satisfied (use --upgrade to upgrade): WebOb>=1.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from WebTest)
Requirement already satisfied (use --upgrade to upgrade): waitress in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from WebTest)
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from WebTest)
Requirement already satisfied (use --upgrade to upgrade): distribute in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg (from waitress->WebTest)
我正在运行我的所有测试,包括没有错误通过的旧测试。但是将webtest
导入其中任何一个都会在顶部生成错误。为什么呢?
答案 0 :(得分:0)
我正在使用带有GAE的webtest,它对我有用。我会尝试找出我的设置与您的设置之间的差异,看看它是否对您有所帮助:
unittest
而不是unittest2
。run_tests.py
这样的脚本。我只是从命令行调用它:nosetests --with-gae
答案 1 :(得分:0)
这对我不同的python环境来说是一个愚蠢的问题。
我路径中的pip
和python
与/user/local/bin/python
相关联。事实上,这就是安装webtest的地方。
我从教程中复制的代码有这个hashbang:#!/usr/bin/python
所以当我用./run_tests.py
运行它时,它运行在webtest 不是的环境中已安装。
运行python ./run_tests.py
或将hashbang更改为#!/user/local/bin/python
解决了问题。