简体   繁体   中英

Flushing python GAE datastore when unit testing

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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