Test doubles for Python standard library HTTP classes
ben+python at benfinney.id.au
Thu Aug 6 10:32:56 CEST 2015
What standard Python library is there to make test doubles of
‘httplib.HTTPConnection’ and ‘urllib2.HTTPBasicAuthHandler’ and so on?
I have a code base (Python 2 code) which performs HTTP sessions using
the various HTTP-level classes in the standard library.
Testing this code will be made much easier if I can create numerous test
doubles with pre-determined behaviour and instrumentation for later
inspection, to allow the functions I'm testing to interact with those
doubles instead of the real thing.
There are some libraries that provide a much higher-level API, but I
need to provide double behaviour at the level this code expects, i.e. at
the level of the API provided by ‘httplib’ and ‘urllib2’ classes.
What standard code libraries provide classes which make it easy to
double the behaviour of ‘httplib’ classes and ‘urllib2’ classes, etc.
for test cases?
 Test double <URL:http://xunitpatterns.com/Test%20Double.html> is a
more general term covering all of stubs, fakes, spies, mocks, etc. to
double specifically as a fixture in a test case.
\ “The most merciful thing in the world… is the inability of the |
`\ human mind to correlate all its contents.” —Howard Philips |
_o__) Lovecraft |
More information about the Python-list