[Web-SIG] WSGI tests

Ian Bicking ianb at colorstudy.com
Wed Sep 29 06:47:55 CEST 2004


I've written some code for testing WSGI applications and servers.  As 
before, it's at svn://colorstudy.com/trunk/WSGI , or 
http://colorstudy.com/cgi-bin/viewcvs.cgi/trunk/WSGI/

The test so far has three parts.  There's a simple "echo" application; 
it actually does several things depending on what variables you give it. 
  There's a "lint" middleware.  It checks for both server and 
application compliance with WSGI.  Then there's a test that fetches 
pages (via urllib) and interprets the response (tests/echotest.py).

The idea is that these can be recombined in some ways.  The echo 
application will probably be expanded to do more things, and to better 
exercise WSGI; e.g., calling start_response twice, using write and 
iterators at the same time, etc.  It could also be expanded to perform 
illegal operations, e.g., call write inside the iterator, to see what 
happens in these cases.

Another option would be some middleware that takes the output of any 
application, and plays around with it to exercise all of WSGI.

Either way, the echo application could be implemented under different 
frameworks, and once it's implemented you could run these other tests 
against your framework.

Then there's the lint middleware.  This doesn't modify the request in 
any way (though it does wrap start_response and other objects).  It just 
checks various things; right now it mostly checks that required 
environmental variables are there and that everything is of the right 
type.  It doesn't test any of the more subtle aspects of WSGI, or test 
any failure cases.  It doesn't test the exc_info stuff either; I haven't 
kept up, and I only partly understand the motivation there.

Then there's the system/functional test (echotest).  Right now it's just 
a bunch of asserts, but I'll refactor it for unittest soon.  The idea is 
that in addition to doing some tests directly against echo, this also 
exercises portions that lint or other middleware is implicitly testing.

Anyway, that's what I got now.  Not a ton of code (despite this long 
email).  Suggestions welcome.

-- 
Ian Bicking  /  ianb at colorstudy.com  / http://blog.ianbicking.org


More information about the Web-SIG mailing list