[Python-Dev] Socket servers in the test suite

Éric Araujo merwok at netwok.org
Thu Apr 28 16:18:15 CEST 2011


Hi,

>> I'm at the point where to appreciably increase coverage, I'd need to write some
>> test servers to exercise client code in SocketHandler, DatagramHandler and
>> HTTPHandler.
>>
>> I notice there are no utility classes in test.support to help with this kind of
>> thing - would there be any mileage in adding such things? Of course I could add
>> test server code just to test_logging (which already contains some socket server
>> code to exercise the configuration functionality), but rolling a test server
>> involves boilerplate such as using a custom RequestHandler-derived class for
>> each application. I had in mind a more streamlined approach where you can just
>> pass a single callable to a server to handle requests,

A generic test helper to run a server for tests would be a great
addition.  In distutils/packaging (due to be merged into 3.3 Really Soon
Now™), we also have a server, to test PyPI-related functionality.  It’s
a tested module providing a server class that runs in a thread, a
SimpleHTTPRequest handler able to serve static files and reply to
XML-RPC requests, and decorators to start and stop the server for one
test method instead of a whole TestCase instance.  I’m sure some common
ground can be found and all these testing helpers factored out in one
module.

> For larger components like this, it's also reasonable to add a
> dedicated helper module rather than using test.support directly. I
> started (and Antoine improved) something along those lines with the
> test.script_helper module for running Python subprocesses and checking
> their output,

+1, script_helper is great.

Cheers


More information about the Python-Dev mailing list