python - App Engine python 本地单元测试 urlfetch_stub.py fancy_urllib 模块没有属性 'InvalidCertificateException'

标签 python testing google-app-engine-python urlfetch

我正在使用安装了 196.0.0-0 版 google-cloud-sdk-app-engine-python 包的 linux。

我尝试根据 [1] 中的引用创建本地单元测试。

class ViewsTestCase(unittest.TestCase):

    def setUp(self):
        self.client = application.test_client()
        self.client.testing = True
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_urlfetch_stub()

    def tearDown(self):
        self.testbed.deactivate()

添加 PYTHONPATH 环境变量:

export PYTHONPATH="$PYTHONPATH:/usr/lib/google-cloud-sdk/platform/google_appengine:/usr/lib/google-cloud-sdk/platform/google_appengine/lib:/usr/lib/google-cloud-sdk/platform/google_appengine/lib/yaml/lib"

然后我尝试运行它。

$ python test_views.py 
Traceback (most recent call last):
  File "test_views.py", line 6, in <module>
    from google.appengine.ext import testbed
  File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/ext/testbed/__init__.py", line 130, in <module>
from google.appengine.api import urlfetch_stub
  File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/urlfetch_stub.py", line 32, in <module>
_fancy_urllib_InvalidCertException = fancy_urllib.InvalidCertificateException
AttributeError: 'module' object has no attribute 'InvalidCertificateException'

我读过这个类似的帖子 [2]。

但是我查了一下,fancy_lib的路径已经固定了。

$ find /usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/__init__.pyc
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/fancy_urllib
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/fancy_urllib/__init__.pyc
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/fancy_urllib/__init__.py
/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib/__init__.py

我尝试将 fancy_urllib 添加到 PYTHONPATH

export PYTHONPATH="$PYTHONPATH:/usr/lib/google-cloud-sdk/platform/google_appengine:/usr/lib/google-cloud-sdk/platform/google_appengine/lib:/usr/lib/google-cloud-sdk/platform/google_appengine/lib/yaml/lib:/usr/lib/google-cloud-sdk/platform/google_appengine/lib/fancy_urllib"

但还是失败了。

有什么线索吗?

谢谢。

[1] https://cloud.google.com/appengine/docs/standard/python/tools/localunittesting

[2] GAE SDK 1.9.5 and an InvalidCertificateException

最佳答案

如果您看到 init.py 的文件长度为“0”并且存在同名的子文件夹(即 lib/fancy_urllib/fancy_urllib),则复制两个文件 (.py , 和 .pyc) 的子文件夹到上层文件夹。那对我有用。

关于python - App Engine python 本地单元测试 urlfetch_stub.py fancy_urllib 模块没有属性 'InvalidCertificateException',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49718980/

相关文章:

python - 有没有办法识别和转换普通字符串中的非转义四位 Unicode 字符?

python - 将高斯拟合到 ROOT 直方图

java - 使用 MockMvc Http Status 错误测试 @ControllerAdvice

java - Pact 契约(Contract)测试入门的先决条件

google-app-engine - 遗留 GCE 元数据服务器端点和 GAE flex 应用程序

django - 如何使用 jinja2 模板调用 django-pipeline compressor

google-cloud-datastore - `gcloud.datastore` 在哪里保留其本地开发状态,我该如何清除它?

python - CNN 可学习参数的数量 - Python/TensorFlow

python-捕获分子的晶格结构-无法正常工作

testing - 如何使用带参数化类型的 assertEqual