Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python中的virtualenv测试我的GAE应用程序_Python_Google App Engine_Testing_Virtualenv - Fatal编程技术网

用Python中的virtualenv测试我的GAE应用程序

用Python中的virtualenv测试我的GAE应用程序,python,google-app-engine,testing,virtualenv,Python,Google App Engine,Testing,Virtualenv,我试图在本地运行的GAE应用程序上使用unittest测试我的数据存储 当我在数据存储上运行简单查询时,我从virtualenv中得到一个错误: Error Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run testMethod() Fi

我试图在本地运行的GAE应用程序上使用unittest测试我的数据存储

当我在数据存储上运行简单查询时,我从virtualenv中得到一个错误:

Error
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/Users/thibault/projects/backend/cron/gmail/test_gmail_api.py", line 40, in test_get_conversation_id_by_email
    res = get_conversation_id_from_email('test@gmail.com')
  File "/Users/thibault/projects/backend/cron/gmail/api_gmail.py", line 158, in get_conversation_id_from_email
    user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
    return wrapped(*args, **kwds)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1218, in fetch
    return self.fetch_async(limit, **q_options).get_result()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
    return wrapped(*args, **kwds)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1238, in fetch_async
    qry = self._fix_namespace()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 922, in _fix_namespace
    namespace = namespace_manager.get_namespace()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/namespace_manager/namespace_manager.py", line 88, in get_namespace
    name = _config.default_namespace_for_request()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 351, in __getattr__
    self._update_configs()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 287, in _update_configs
    self._registry.initialize()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 160, in initialize
    import_func(self._modname)
  File "/Users/thibault/projects/backend/appengine_config.py", line 8, in <module>
    vendor.add('lib')
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/vendor/__init__.py", line 44, in add
    'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory
测试功能:

def get_conversation_id_from_email(email_user):
    """
    Args:
      email_user: the email user

    Returns:
       the conversation id
    """
    user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
    if len(user_list) == 0:
        return None
    for user_match in user_list:
        return user_match.device_ids[0]

在项目的根目录中创建
appengine\u config.py
,并放置以下内容:

import os
from google.appengine.ext import vendor

vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
另外,若项目根目录不存在,则将
lib
包添加到项目根目录中


在我的例子中,它解决了这个问题。

在项目的根目录中创建
appengine\u config.py
,并将其放入:

import os
from google.appengine.ext import vendor

vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
另外,若项目根目录不存在,则将
lib
包添加到项目根目录中


在我的例子中,它解决了这个问题。

显示文件夹结构,库在哪里?显示文件夹结构,库在哪里?