Google Push-To-Deploy Pipelines - Unit tests fail with module import error

主宰稳场 提交于 2019-12-10 17:39:17

问题


I get the following error when I try to execute a build on the Google provisioned Jenkins servers in Compute Engine.

[deployment_5371449468518400_1411607125060] $ /bin/sh -xe /tmp/hudson807438832151987098.sh
+ nosetests --with-xunit --xunit-file=nosetests.xml
E
======================================================================
ERROR: Failure: ImportError (No module named google.appengine.ext)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/var/jenkins/workspace/deployment_5371449468518400_1411607125060/tests.py", line 9, in <module>
    from google.appengine.ext import ndb
ImportError: No module named google.appengine.ext

----------------------------------------------------------------------
Ran 1 test in 0.448s

I am confident that this is happening because of the following line in my tests.py

from google.appengine.ext import ndb

Please help.

I am including a link to a doc which has more details


回答1:


Joseph, as the path is not set correctly, please add this to the beginning of your tests.py file:

import sys
sys.path.append("/google-cloud-sdk/platform/google_appengine")

Please, don't forget to add this part before trying to import anything from that library as the path wouldn't be configured yet.

In other words:

import sys
sys.path.append("/google-cloud-sdk/platform/google_appengine")

some other imports
#next import ONLY after the path has been updated to point to the App Engine libraries
from google.appengine.ext import ndb


来源:https://stackoverflow.com/questions/26029120/google-push-to-deploy-pipelines-unit-tests-fail-with-module-import-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!