使用py.test在python中测试和调试数据存储区代码的问题

时间:2017-02-22 15:54:31

标签: python-3.x google-app-engine google-cloud-datastore

我使用Python中的google cloud datastore对一些py.test PyCharm代码进行单元测试。代码在datastore emulator本地运行。问题是

  1. 我必须在执行time.sleep(num_secs)put_multi()等代码之后放置多个put(),并在调试模式下运行代码,逐行检查结果以便{ {1}}不会失败,因为即使代码正确运行,使用assertemulator返回的结果也不会反映query.fetch()中的更改。我意识到datastorePython之间可能会出现竞争状况。因此,使变更有效(大?)延迟?
  2. 有时,即使在调试模式下使用datastore simulator,我也遇到了emulator。然后我必须打开HTTP Error 404: Service Unavailable虚拟机,因此代码可以再次运行,甚至之后关闭虚拟机。这很奇怪。请注意,当Compute Engine已与App Engine
  3. 相关联时,就会发生这种情况

    我想知道在project_id中调试和测试datastore代码的最佳方法是什么。

1 个答案:

答案 0 :(得分:2)

对于#1,数据存储模拟器会加剧eventual consistency对某一部分操作的影响。来自gcloud beta emulators datastore start

  

--consistency = CONSISTENCY;默认=" 0.9"

Fraction of datastore operations that should succeed.