google-app-enginepython-2.7unittest2

No api proxy found for service "memcache" GAE unittest2


I'am trying to write tests to my app. I make a simple test case:

def test_put(self):
    Result(
        id="23738",
        target_id="23738",
    ).put()

and after running, it raises an error:

AssertionError: No api proxy found for service "memcache"

I don't know, how to fix it.

And this is my set_up:

def set_up(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_user_stub()

and tear_down:

def tear_down(self):
    self.testbed.deactivate()

Solution

  • The function names in your code are:

    def set_up(self):
       ...
    
    def tear_down(self):
       ...
    

    However, according to the Python unittest documentation, the proper names are setUp and tearDown (note the lack of underscore and camelCase).

    You can see similar uses of the functions in the AppEngine Python local unit testing documentation.