3

我无法理解这个错误:

======================================================================
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 应用设置处理程序单元测试。
  • 我正在关注本教程以获取单元测试框架,包括页面底部的 bash 脚本,逐字逐句。
  • 我正在使用以下命令从终端运行测试:

    ./run_tests.py /usr/local/google_appengine test/

  • 我正在使用本教程来构建我的处理程序测试。但它永远不会超过进口。我所要做的就是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其中任何一个都会在顶部生成错误。为什么?

4

2 回答 2

0

I'm using webtest with GAE and it is working for me. I'll try to identify differences between my setup and yours to see if that helps you:

  • I'm using unittest and not unittest2.
  • I'm not using a script like your run_tests.py. I just call it from the command line like this: nosetests --with-gae
于 2013-03-24T18:24:10.417 回答
0

事实证明,这对于我的不同 python 环境来说是一个愚蠢的问题。

我的路径中的pipandpython链接到/user/local/bin/python. 实际上,这就是安装 webtest 的地方。

然而,我从教程中复制的代码有这个 hashbang:#!/usr/bin/python所以当我用 运行它时,它运行在没有安装webtest./run_tests.py的环境中。

运行python ./run_tests.py或更改 hashbang 以#!/user/local/bin/python解决问题。

于 2014-04-02T17:38:25.880 回答