Best way to disable settings from appengine_config during tests

40 views
Skip to first unread message

Andi Albrecht

unread,
Oct 30, 2011, 2:18:19 AM10/30/11
to google-appengine
Hi all,

I have set up local unit tests for a Python app according to the
documentation on the App Engine site [1]. The app has appstats
configured as a WSGI middleware through appengine_config.py by using
the webapp_add_wsgi_middleware() directive:

def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app

When running the tests I want to disable appstats. appstats needs
REQUEST_ID_HASH environment variable which isn't set during tests, but
recording data doesn't make much sense at all during tests.

The current idea is to monkey-patch
appengine_config.webapp_add_wsgi_middleware when it's first imported
by the test runner - before any test is actually executed:

import appengine_config
appengine_config.webapp_add_wsgi_middleware = lambda app: app

But I wonder if there are better (or more documented) alternatives to
modify settings from appengine_config.py during tests.

--Andi

[1] http://code.google.com/appengine/docs/python/tools/localunittesting.html

Sun Jing

unread,
Oct 30, 2011, 4:14:34 AM10/30/11
to google-a...@googlegroups.com

You can try:

def webapp_add_wsgi_middleware(app):
  if not appos.environ['APPLICATION_ID'].startswith('dev~'):
    app = recording.appstats_wsgi_middleware(app)
  return app

----------
keakon

My blog(Chinese): www.keakon.net




--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.


Andi Albrecht

unread,
Oct 31, 2011, 12:35:07 AM10/31/11
to google-a...@googlegroups.com
That's an interesting idea. I'd just do it the other way round and add appstats only iff APPLICATION_ID doesn't starts with 'test-' since I'm already setting this prefix when setting up the test environment.

Thanks!

Andi
Reply all
Reply to author
Forward
0 new messages