简体   繁体   English

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

[英]Flushing python GAE datastore when unit testing

I am following the recommendations on the app engine site for unit testing coding with GAE . 我正在遵循App Engine网站上有关使用GAE进行单元测试编码的建议 I have set the PseudoRandomHRConsistencyPolicy probability to 0% to force the code to account for cases where the data is not yet consistent. 我已将PseudoRandomHRConsistencyPolicy概率设置为0%,以强制代码考虑数据不一致的情况。 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? 有什么方法可以做到,如果没有,其他人在使用一致性模型时如何在他们的测试套件中设置数据?

The key to doing this is noted near the end of the section on HRD testing: 在HRD测试部分的结尾处将指出执行此操作的关键:

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. 在本地环境中,使用未应用的写操作执行属于某个实体组的Entity的get()总是会使未应用的写操作的结果对后续的全局查询可见。 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. 只需在测试中添加一些get操作即可获取适当的记录,它们将显示在以后的查询中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM