[Web-SIG] Re: PEP 333 / unittest
Ian Bicking
ianb at colorstudy.com
Wed Oct 20 19:13:40 CEST 2004
Phillip J. Eby wrote:
> At 11:58 AM 10/20/04 -0400, Greg Wilson wrote:
>
>> Hi Phillip. Hope you don't mind mail out of the blue, but I was
>> wondering
>> if anyone had already done work to integrate WSGI and the unit test
>> framework, i.e. built a mock-WSGI that could be dropped directly into
>> unittest?
Kind of, depending on which part of WSGI is "mock". The echo
application is intended to be, essentially, a mock application. There
are unittests that work against that application, implicitly testing the
WSGI server.
lint checks for more compliance issues, mostly trying to determine that
errors don't quietly pass through (e.g., not supplying a content type, a
problem which many servers and browsers will cover up).
wsgilib.interactive is something I've created for inspecting
applications. I think wsgiref has somthing similar -- just creating a
mock request, and providing a response. It would be nice to make a
response object that was appropriate for testing -- that might mean easy
methods to test for a string in the response, check for general success
(e.g., 200 status code, no applicatinon-generated errors, etc), maybe
check what shows up in the error log.
From there, you could make a unittest.TestCase subclass that automated
this a bit further, so you could quickly write acceptance/functional tests.
But, a lot of the acceptance test work could be done through HTTP
directly, and wouldn't be much more difficult to implement. The
advantage to using WSGI instead of HTTP would be in saving some work
doing configuration. That's very possibly worth it, since configuring a
test environment is annoying (since you'll never actively use it). But
since HTTP and WSGI are so close, it might be nice to allow either to be
tested using the same framework.
My code is in svn://colorstudy.com/trunk/WSGI ; Peter Hunt has also done
some stuff similar to the echo tests, in
svn://colorstudy.com/trunk/WSGI/phunt/test_applications.py
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Web-SIG
mailing list