我正在使用 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/