单元测试时刷新 python GAE 数据存储

发布于 2024-12-06 08:52:07 字数 380 浏览 1 评论 0原文

I am following the recommendations on the app engine site for unit testing coding with GAE. I have set the PseudoRandomHRConsistencyPolicy probability to 0% to force the code to account for cases where the data is not yet consistent. The problem is that in my test suite I want to do some data setup (creating and adding data to the datastore) and need a way to force the datastore to flush all the data into a consistent state before I exercise the code under test. (ie. make sure that the datastore will return all global entities I have written the next time I do a query).

Is there any way to do this and if not, how are other people setting up data in their tests suites when they are using the consistency models?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2024-12-13 08:52:07

做到这一点的关键在 HRD 测试部分的末尾指出:

在本地环境中,执行实体的 get()
属于具有未应用写入的实体组将始终使
未应用的写入结果对后续全局可见
查询。在生产中情况并非如此。

只需在测试中添加一些获取操作即可获取适当的记录,它们将显示在将来的查询中。

The key to doing this is noted near the end of the section on HRD testing:

In the local environment, performing a get() of an Entity that
belongs to an entity group with an unapplied write will always make
the results of the unapplied write visible to subsequent global
queries. In production this is not the case.

Simply add some get operations to your tests to get the appropriate records, and they will show up in future queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文