python - App Engine 中的处理程序测试失败 : webtest import errors

标签 python google-app-engine web-testing

我无法理解这个错误:

======================================================================
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'

情况是:

  • 我正在尝试为我的 App Engine 应用设置处理程序单元测试。
  • 我正在关注 this tutorial对于单元测试框架,包括 页面底部的 bash 脚本,逐字记录。
  • 我正在使用以下命令从终端运行测试:

    ./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 导入其中的任何一个都会在顶部产生错误。为什么?

最佳答案

我正在将 webtest 与 GAE 结合使用,它对我很有效。我将尝试找出我的设置与您的设置之间的差异,看看是否对您有帮助:

  • 我使用的是 unittest 而不是 unittest2
  • 我没有使用像您的run_tests.py 这样的脚本。我只是像这样从命令行调用它:nosetests --with-gae

关于python - App Engine 中的处理程序测试失败 : webtest import errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15465892/

相关文章:

Selenium 或茄子

python - 使用 pandas cut 对值进行分组

python - 排除 Pandas 数据框中索引行的最有效方法

python - 在 Google Cloud Datastore 与 Google Cloud Bigtable 中存储用户事件历史记录

python - 如何在 django 模板中获取引用属性

python - 无法将我的应用程序部署到 Google App Engine

java - 如何使用 Selenium 测试在 span 元素中选择值?

python - 为什么 python int() 方法不喜欢 base =0 中的数字 05000408

python - pandas 通过循环列表中的名称来生成数据帧

java - 用于爬网的 headless Java HTTP 客户端?