Task queue works from view, but UnknownQueueError when run from unit tests
Updated: Originally I didn't realize this only fails when run from unit tests.
I have a working task queue in AppEngine with Python.
- When calling a view manually, the task is added to the queue and runs
- When called from unit tests, adding the task to the queue fails with an UnknownQueueError.
When reading about others who've encountered the UnknownQueueError issue, there have been some suggestions of overriding taskqueue_stub
to fix this. But I'm no开发者_开发百科t sure exactly how this should be done or why.
Edit: working answer. My problem was adding the stub fix in an individual unit test: moving it to setUp() fixed things.
In tests.py
from google.appengine.api import apiproxy_stub_map
import os
class BlahTest(MyAppTestCase)
def setUp(self):
'''Ensure dev appserver task queue knows where to find queue.yaml'''
taskqueue_stub = apiproxy_stub_map.apiproxy.GetStub( 'taskqueue' )
dircontainingqueuedotyaml = os.path.dirname(os.path.dirname( __file__ ))
taskqueue_stub._root_path = dircontainingqueuedotyaml
This now works.
精彩评论