[twill] Access to the WSGI environment with wsgi_intercept

Titus Brown titus at caltech.edu
Thu Jan 3 21:08:58 PST 2008

On Thu, Jan 03, 2008 at 03:54:35PM -0600, Ken Kuhlman wrote:
-> I've been trying to do a better job of testing my (turbogears) web apps
-> lately, and am trying to decide if I should be using twill or paste.fixture.
-> I like a lot of things about twill, but one of the key strengths of paste
-> (IMHO) is that it's "in process" testing feature includes the ability to
-> dump the wsgi environment (unlike wsgi_intercept, which otherwise is a very
-> nice hack).   Access to the environ is very handy [1] when you're doing MVC
-> work & trying to seperate what the controller's doing from what the rendered
-> result looks like.
-> Anyway, code speaks louder than words, so I've included an example of what
-> I'd like to see, and a patch to twill to make it work.   I'd be interested
-> to know if you all think I'm on the right track or if I'm all wet.  I'm a
-> twill & wsgi n00b, so my apologies if I've missed anything obvious.

Hey Ken!  Good idea, and one that I think can be generalized nicely...
which is why I want to think about it a bit more before committing to
any one direction.  We should include Kumar, too, because he's taken
over wsgi_intercept - Kumar, are you on this list?

First, I don't want to include a default command that deals with WSGI,
because most people probably won't know what it is or use it.  We could
still create an extension module, but there are some other questions...

For example, you may want to have multiple WSGI apps in play, in which
case your global environ hack would cause problems.  (This is why
_wsgi_intercept, which contains the apps, is the only global one.)

And why not use middleware instead of a solid hook?  Something like

# install 'simple_app' with an environment printer under 'foo_name'
app_fn = lambda: twill.wsgi.env_printer('foo_name', simple_app)
twill.add_wsgi_intercept('localhost', 8001, lambda: app_fn)

Then we could have twill_wsgi functions, e.g.

val = twill_wsgi.print_environ('foo_name', 'env_variable_to_print')

or twill script,

>> extend_with twill_wsgi
>> print_environ foo_name env_variable_to_print



More information about the twill mailing list