python - 通过 Nose 测试与多个实体组运行事务时出错

标签 python google-app-engine nose

我正在使用 Google App Engine 框架使用 Python 2.7 构建一个应用程序。 为了测试我的应用程序,我使用 nosegae 插件通过 nosetests 运行了几个测试。我使用以下命令运行它们:

nosetests --with-gae --gae-lib-root=/usr/local/google_appengine/ -w . -w */test/ -v

在我的应用程序的模型层中,我需要运行多个影响同一事务内多个实体组的数据库操作。我通过使用 db 包的 run_in_transaction_options 函数来做到这一点: https://developers.google.com/appengine/docs/python/datastore/functions#run_in_transaction

不幸的是,在运行我的测试套件时,我在那些尝试运行此类事务的测试用例中遇到以下错误:

BadRequestError: transactions on multiple entity groups only allowed with the High Replication datastore

我在 nosetests 中找不到任何可以启用 HRD 的标志。

我想知道是否可以从 nosetests 运行 HRD,如果可以,如何设置?

最佳答案

我强烈建议您从 db 切换到 ndb,您可以在其中使用 cross group transactions .

要模拟 HRD,您可以将此部分添加到测试的 setUp 函数中,来自 Writing High Replication Datastore tests :

# Create a consistency policy that will simulate the High Replication consistency model.
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)

# Initialize the datastore stub with this policy.
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

关于python - 通过 Nose 测试与多个实体组运行事务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12695592/

相关文章:

用 Nose : Making sequential tests 进行 Python 单元测试

python - 切片列表中的所有字符串?

java - Google Eclipse 插件 : Browser Plugin vs. 开发模式

python - 覆盖范围是跳过返回语句

python - 谷歌应用引擎 : UnicodeDecode Error in bulk data upload

python - 如何在 Google App Engine 上的 python 中使用 bdutil 和 gcloud?

python - 在 Autodesk Maya 等 Python 环境中使用 Nose 运行单元测试?

python - 在 Python 中训练 OpenCV NormalBayesClassifier

java - Python:如何通过 python 脚本执行 jar 文件

python - 有孔结果的匀称多边形并集