python - How to Clear/Invalidate NDB Cache in Tests -
i have simple ndb model instance attribute, not ndb property. want test property value gets lost when entity saved , retrieved datastore.
now when entity retrieved same instance 1 has been put datastore.
is there way programatically clear/invalidate memcache , ndb in-memory cache?
the example pytest test, sorry that.
from google.appengine.ext import testbed, ndb class user(ndb.model): name = ndb.textproperty() foo = none class testndbmodel(object): def setup(self): self.testbed = testbed.testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() def teardown(self): self.testbed.deactivate() def test_foo(self): user = user(name='andy') assert user.name == 'andy' assert user.foo none user.foo = 123 assert user.foo == 123 user_key = user.put() # here need clear cache somehow, # entity must retrieved datastore retrieved_user = user_key.get() # these 2 fail assert retrieved_user not user assert retrieved_user.foo none
you're apparently using wrong method assign value retrieved_user
. use following instead:
retrieved_user = user_key.delete(use_datastore=false)
see following link more information:
https://developers.google.com/appengine/docs/python/ndb/functions#context_options
Comments
Post a Comment